MTclockDouble: Example 2
Event management for Uno, Nano, Mega
Flashs and button
This program will make LED_BUILTIN flash when a button is pressed.
We will use a button that controls a double metronome, one in two events will light the LED, one in two events will turn it off. It is a classic example that can be used as a basis for tasks such as programming a fan, an engine ...
Complete program recommended
This program is completely under interruption, and releases loop which can be used to do something else.
// This program will make LED_BUILTIN flash when a button is pressed #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 // The metronome make the Led flash void lightOn(void) { digitalWrite(LED_BUILTIN, HIGH); } void lightOff(void) { digitalWrite(LED_BUILTIN, LOW); } MTdoubleClock Metronome(100 milli_seconds, 10 milli_seconds, lightOn, lightOff, MT_INFINI, MT_OFF); // The button activates or deactivates metronome void flashOn(void) { Metronome.start(); } void flashOff(void) { Metronome.stop(); lightOff(); } MTbutton Bouton(PIN_BUTTON, flashOn, flashOff); void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop(){}