Hi,
I'm attempting to use Nick Gammon's SwitchManager.h library for a project. The library can be found here: [http://gammon.com.au/Arduino/SwitchManager.zip]
When I setup my project as per the comments in the SwitchManager.h library everything works great.
#include <SwitchManager.h>
//object instantiations
SwitchManager myIncSwitch;
SwitchManager myDecSwitch;
unsigned long currentMillis;
unsigned long incLongPress = 2000UL;// 2 seconds
const byte incSwitch = 32;
const byte decSwitch = 36;
int myCounter;
//======================================================================
void setup()
{
Serial.begin(9600);
myIncSwitch.begin (incSwitch, switchOneHandler);
myDecSwitch.begin (decSwitch, switchTwoHandler);
}
void loop()
{
//leave this line of code at the top of loop()
currentMillis = millis();
myIncSwitch.check ();
myDecSwitch.check ();
}
void switchOneHandler(byte newState, unsigned long interval, byte whichPin)
{
if (newState == HIGH)
{
if(interval >= incLongPress)
{
Serial.println("Switch 1 pressed.");
}
}
}
void switchTwoHandler(const byte newState, const unsigned long interval, const byte whichPin)
{
if (newState == HIGH)
{
if(interval >= incLongPress)
{
Serial.println("Switch 2 pressed.");
}
}
}
I'm attempting to put this code inside of a wrapper class to keep things clean, but keep running into an "invalid use of non-static member function" when I try and initialize my buttons in the wrapper's constructor.
ButtonManager::ButtonManager()
{
btnOne.begin(btnOne, btnOneHandler);
}
lib/ButtonManager/ButtonManager.cpp: In constructor 'ButtonManager::ButtonManager()':
lib/ButtonManager/ButtonManager.cpp:48:73: error: invalid use of non-static member function
btnOne.begin(btnOne, btnOneHandler);
How do I get rid of this error?
Thanks so much in advance for your help!!