#include <mechButton.h>
#define LED 3 // Pin # for LED.
mechButton redBtn(2); // Set up the button on pin 2
timeObj LEDTimer(500); // Timer for holding LED on.
void setup() {
pinMode(LED,OUTPUT); // Make LED pin output.
digitalWrite(LED,LOW); // Make sure the damn thing's off.
redBtn.setCallback(btnClicked); // Hookup the button's callback funtion.
}
// Button callback.
void btnClicked(void) {
if (!redBtn.trueFalse()) { // If the button was pressed..
digitalWrite(LED,HIGH); // Turn on the LED.
LEDTimer.start(); // Start the timer.
}
}
void loop() {
idle(); // Do magic..
if (LEDTimer.ding()) { // If the timer goes "ding", as timers do..
digitalWrite(LED,LOW); // Shut off the LED.
LEDTimer.reset(); // Turn off the timer.
}
}