AttachInterrupt in a library I'm having trouble adding attachInterrupt in a library that I am creating. I researched a lot, and I noticed that this is a common mistake, but do not quite understand the answers I found.

The error in question is this:

sketch_nov04a.ino: In function 'void setup()':
sketch_nov04a:10: error: argument of type 'void (Teste::)()' does not match 'void (*)()'


My library is as follows: 

Teste.h

#ifndef TESTE_H
#define TESTE_H
#include &lt;Arduino.h&gt;

class Teste
{
public:
    volatile long lastWindIRQ;
    volatile byte windClicks;

  void wspeedIRQ();
};
#endif


Teste.cpp

#include "Teste.h"

void Teste::wspeedIRQ()
{
  if (millis() - this.lastWindIRQ &gt; 10)
  {
    this.lastWindIRQ = millis();
    this.windClicks++;
  }
}


my implementation

#include &lt;Teste.h&gt;

Teste teste;

void setup()
{
  Serial.begin(9600);
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, teste.wspeedIRQ, FALLING);
}

void loop()
{
  Serial.println(teste.windClicks);
  delay(3000);
}


EDIT: Updated the error and corrected the problem cited by Ignacio
The problem is that wspeedIRQ() is a member function (i.e. it's part of the Teste class), but attachInterrupt() expects a non-member function (i.e. a function which is static and/or not part of a class at all).

This is a very important distinction in C++ because it affects how the compiler calls the function behind-the-scenes. There is unfortunately no way to use a member function directly with attachInterrupt().

Various workarounds are possible though. The simplest is to write a wrapper function which calls the member function. For example:

Teste teste;

// This is a non-member function...
void isr()
{
    // ...which calls the member function:
    teste.wspeedIRQ();
}

void setup()
{
    //...

    // Setup interrupt to use a non-member function
    attachInterrupt(0, isr, FALLING);
}


As a side note, your implementation of wspeedIRQ() won't compile at the moment anyway. The reason is that this. is invalid. It's a pointer so the correct syntax is this-&gt;.

(In practice, you usually don't need to use this to access member data. C++ figures it out automatically, unless there's a naming conflict.)