#include <mechButton.h>
mechButton ourBtn(2);
timeObj firstTimer(500,false);
timeObj secondTimer(400,false);
void setup() {
Serial.begin(115200); // Fire up serial port.
ourBtn.setCallback(btnClk); // Tell the button what callback to ue on change.
}
void btnClk(void) {
if (ourBtn.getState()) { // Button lifted.
if (!firstTimer.ding()&&firstTimer.getFraction()!=1) { // If lifted and some time spent before first timer expired..
newPage(); // Call new page.
} //
firstTimer.reset(); // Reset timers.
secondTimer.reset(); // Going back to rest state.
} else { // OH ohh! Button pressed!
firstTimer.start(); // We start the first timer.
} //
}
void newPage(void) { Serial.println("New Page."); }
void bumpVariable(void) { Serial.println("Bump variable."); }
void loop() {
idle(); // Do the magic. (Runs things like the button.)
if (firstTimer.ding()) { // If first timer has gone off..
secondTimer.start(); // Start second timer.
firstTimer.reset(); // Shut down first timer.
bumpVariable(); // Do initial variable bump.
} //
if (secondTimer.ding()) { // If the second timer goes off..
bumpVariable(); // We bump the variable.
}
// Do whatever you need here. But DON"T CALL delay()!!
// But you can call sleep(). Works the same way but don'y mess up the button stuff.
}