MTdoubleButton: Example 1
Event management for Uno, Nano, Mega
Turn off with a double click
A button is connected between A0 and GND. The program will light the LED_BUILTIN LED on double click and turn it off on a single click.
Complete program recommended
This program is completely under interruption, and releases loop which can be used to do something else.
// This program lights an LED if you double click and turn off the LED // on a single click. #include <MTobjects.h> // V1.0.6 See http://arduino.dansetrad.fr/en/MTobjects const uint8_t PIN_BUTTON = A0; // Button wired between A0 and GND void turnOn(void) // Call on double-click { digitalWrite(LED_BUILTIN, HIGH); // Turn on } void turnOff(void) // Call on simple-click { digitalWrite(LED_BUILTIN, LOW); // Turn off } MTdoubleButton Bouton(PIN_BUTTON, turnOn, turnOff); // Implementation of the button void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop(){}