MTclockDouble: Example 3
Event management for Uno, Nano, Mega
Flashs and on/off
Flashing LED with on/off button.
We will use a bistable 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.
// Flashing LED_BUILTIN with on/off button #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 lightOn(void) { digitalWrite(LED_BUILTIN, HIGH); } void lightOff(void) { digitalWrite(LED_BUILTIN, LOW); } MTdoubleClock Metronome(500 milli_seconds, 100 milli_seconds, lightOn, lightOff, MT_INFINI, MT_OFF); void flashOn(void) { Metronome.start(); } void flashOff(void) { Metronome.stop(); lightOff(); } MTcheckButton Bouton(PIN_BUTTON, flashOn, flashOff); void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop(){}