MTclock: Example 1
Event management for Uno, Nano, Mega

5 letters with
5 metronomes

This program will send a letter every second on the console. There are 5 letters to send from A to E.

Principle: a monostable wait 1s then sends the letter A and triggers the second monostable. The monostable wait 1s, sends the letter B and triggers the third monostable and so on. There are 5 letters to send, we will use 5 monostables. It is more for educational purposes to show that if MTobjects has a simple clock and a double clock, you can easily make triple, quadruple, fivefold as here ... If we had to do the best program responding to this statement, I would use a metronome and a modulo 5 counter which would indicate the letter to send.

Complete program recommended

This program is completely under interruption, and releases loop which can be used to do something else.

// This program will send continusly 5 letters

#include <MTobjects.h> // V1.0.6 See http://arduino.dansetrad.fr/en/MTobjects

void sendE(void); // Predefinition because it contains reference to MonostableA
MTclock MonostableE(1000 milli_seconds, sendE, 1 action_and_stop, MT_OFF);

void sendD(void) { Serial.print('D'); MonostableE.start(); }
MTclock MonostableD(1000 milli_seconds, sendD, 1 action_and_stop, MT_OFF);

void sendC(void) { Serial.print('C'); MonostableD.start(); }
MTclock MonostableC(1000 milli_seconds, sendC, 1 action_and_stop, MT_OFF);

void sendB(void) { Serial.print('B'); MonostableC.start(); }
MTclock MonostableB(1000 milli_seconds, sendB, 1 action_and_stop, MT_OFF);

void sendA(void) { Serial.print('A'); MonostableB.start(); }
MTclock MonostableA(1000 milli_seconds, sendA, 1 action_and_stop, MT_ON);

void sendE(void) { Serial.println('E'); MonostableA.start(); }


void setup()
{
  Serial.begin(115200);
}

void loop(){}