MTclockDouble: Example 5
Event management for Uno, Nano, Mega
Bursts with on/off
We want to make a blinking LED with flashes controlled by a on/off button. When it flashes, the chronogram looks like:
To make the flashes, we will use a first clock that will deliver 5 flashes and then that will stop. To make the global flashing, a second clock will trigger the first every two seconds. Finally, to manage the on/off, a button will activate or not the second clock.
Complete program recommended
This program is completely under interruption, and releases loop which can be used to do something else.
// Bursts with on/off
#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
// FiveFlashes is the part that makes the LED flash
void lights(void)
{
digitalWrite(LED_BUILTIN, HIGH);
}
void extinct(void)
{
digitalWrite(LED_BUILTIN, LOW);
}
MTdoubleClock FiveFlashes(100 milli_seconds, 50 milli_seconds, lights, extinct, 10 actions_and_stop, MT_OFF);
// Metronome is responsible for the general flashing
void flashes(void)
{
FiveFlashes.start();
}
MTclock Metronome(2000 milli_seconds, flashes, MT_INFINI, MT_OFF);
// Button allows general run or stop
void run(void)
{
FiveFlashes.start(); // To flash upon starting
Metronome.start();
}
void stop(void)
{
Metronome.stop();
}
MTcheckButton Bouton(PIN_BUTTON, run, stop);
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){}