I'm trying to create a class that uses attachInterrupt, but get this error msg:
In member function 'void ledDoor::attach()':
ClosetLedStrip:31:82: error: invalid use of non-static member function
attachInterrupt(digitalPinToInterrupt(_sensorPin), detection_door, CHANGE);
^
exit status 1
invalid use of non-static member function
I found few answers regarding static member, but it was not clear for my needs.
Appreciate help,
#define USE_SLEEP true
#if USE_SLEEP
#include <avr/sleep.h>
#endif
#define sensorPin_1 2
#define sensorPin_2 3
#define RelayON HIGH
#define doorOpen HIGH
#define pwrdown_timeOut 10*(1000*60) // mins to powerdown
// volatile boolean detectDoor_1_Open = false;
//volatile boolean detectDoor_2_Open = false;
const int relayPin1 = 4;
const int relayPin2 = 5;
class ledDoor {
private:
int _sensorPin;
int _interruptPin;
int _relPin;
void attach(){
attachInterrupt(digitalPinToInterrupt(_sensorPin), detection_door, CHANGE);
}
void detection_door(){
#if USE_SLEEP
sleep_disable();
#endif
detachInterrupt(digitalPinToInterrupt(_sensorPin));
if (digitalRead(_sensorPin) == doorOpen) {
_doorOpen = true;
}
else {// trun off
_doorOpen = false;
}
attach();
}
public:
bool volatile _doorOpen;
ledDoor(int sensorPin, int relPin){
_sensorPin=sensorPin;
_relPin=relPin;
pinMode(_relPin, OUTPUT);
pinMode(_sensorPin, INPUT); // sensor io
attach();
}
void go2sleep() {
#if USE_SLEEP
sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_cpu();
#endif
}
void switchLeds(){
if (_doorOpen == true) {
digitalWrite(_relPin, RelayON);
}
else{
digitalWrite(_relPin, !RelayON);
}
}
};
ledDoor door1(sensorPin_1, relayPin1);
ledDoor door2(sensorPin_2, relayPin2);
void setup() {
Serial.begin(9600);
Serial.println("UP");
}
void loop() {
door1.switchLeds();
door2.switchLeds();
#if USE_SLEEP
door1.go2sleep();
door2.go2sleep();
#endif
}