Hi guys,
I am creating the class MyOptocoupler supposed to manage the optocoupler on my robot. I have created a methode begin() for the pinMode declaration and the attacheInterrupt function, but I have got an error:
C:\Users\USER\Documents\Arduino\libraries\MyOptocoupler\MyOptocoupler.cpp: In member function 'void MyOptocoupler::begin(int)':
C:\Users\USER\Documents\Arduino\libraries\MyOptocoupler\MyOptocoupler.cpp:29:31: error: cannot convert 'void (MyOptocoupler::*)()' to 'void (*)()' for argument '2' to 'void attachInterrupt(uint8_t, void (*)(), int)'
attachInterrupt(0, p, CHANGE);
^
Erreur lors de la compilation.
So do you know how to convert void (MyOptocoupler::)() to void ()() ?
I give you my code :
MyOptocoupler.h
#ifndef MyOptocoupler_h
#define MyOptocoupler_h
#if defined(__AVR__)
#include "Arduino.h"
#elif defined(__PIC32MX__)
#include "WProgram.h"
#elif defined(__arm__)
#include "Arduino.h"
#endif
class MyOptocoupler
{
public:
MyOptocoupler(int pin);
void begin();
void begin(int goalOfCount);
void changement();
bool isOutOfCount();
private:
int _pin;
int _goalOfCount;
volatile int _counter;
};
#endif
My Optocoupler.cpp:
#include "MyOptocoupler.h"
MyOptocoupler::MyOptocoupler(int pin): _pin(pin), _counter(0)
{
}
void MyOptocoupler::begin()
{
//Does not metter it will be quite the same as begin(int goalOfCount)
//_goalOfCount = 0;
//pinMode(_pin, INPUT);
//attachInterrupt(digitalPinToInterrupt(_pin), changement, CHANGE);
}
void MyOptocoupler::begin(int goalOfCount)
{
_goalOfCount = goalOfCount;
pinMode(_pin, INPUT);
void (MyOptocoupler::*p)();
p = &MyOptocoupler::changement;
attachInterrupt(0, p, CHANGE);
}
void MyOptocoupler::changement()
{
_counter++;
}
bool MyOptocoupler::isOutOfCount()
{
return _counter >= _goalOfCount;
}
Thank you so much for your help.
Frank