MTdoubleClock
Event management for Uno, Nano, Mega
Clock like metronome how can alternately call two functions..
Include to add
#include <MTobjects.h> // See http://arduino.dansetrad.fr/en/MTobjects
I strongly advise to leave the comment, if another person wanted to try the program, they would have a download link directly. This is valid for all the libraries you use.
Useful comments
milli_second milli_seconds action_and_stop actions_and_stop
These comments are words that can be added anywhere and which are ignored by the compiler.
Constructor
MTdoubleClock(interval1_ms, interval2_ms, onTimeFunction1 = NO_ACTION, onTimeFunction2 = NO_ACTION, numberOfActions = MT_INFINI, active = MT_ON);
- interval1_ms, interval2_ms (unsigned long): time intervals between actions in milliseconds
- onTimeFunction1, onTimeFunction2: what is happening regularly
- NO_ACTION → nothing happens
- myFunction → call a function "void myFunction(void) {...}"
- numberOfActions (unsigned long): number of actions before it deactivates
- MT_INFINI → infinite number, it does not deactivate on its own
- <valeur numérique> → it deactivates after the number of actions
- 1 → for a single shoot
li> active (boolean): run or not - MT_ON → clock active, calls user functions
- MT_OFF → inactive, for example for the single shoot. We activate it by MTclock.start();
Useful functions
void start(void); void stop(void); virtual void onTime1(void); virtual void onTime2(void);
start: activates the clock
stop: disable the clock
onTime1: an,d onTime2: function to be overloaded called at the end of the count
Bonus functions
void setInterval1_ms(unsigned long interval_ms); void setInterval2_ms(unsigned long interval_ms); void setInterval1_ms(); void setInterval2_ms(); unsigned long getInterval1_ms(); unsigned long getInterval2_ms(); void setOnTimeFunction1(onTimeFunction); void setOnTimeFunction2(onTimeFunction); void setOnTimeFunction1(); void setOnTimeFunction2(); void setNumberOfActions(unsigned long numberOfActions); void setNumberOfActions(); unsigned long getNumberOfActions(); unsigned long getNumberOfActionsRemains(); boolean getActive();
setInterval1_ms, setInterval2_ms: change the basic time, 1s by default
setInterval1_ms, setInterval2_ms: without parameter puts 1s for the time base
getInterval1_ms, getInterval2_ms: returns the time interval in ms
setOnTimeFunction1, setOnTimeFunction2: changes the function called regularly
setOnTimeFunction1, setOnTimeFunction2: without parameter removes the call
setNumberOfActions: change the number of calls to make
setNumberOfActions: infinite if there are no parameters
getNumberOfActions: return the number of calls to be programmed
getNumberOfActionsRemains: return the number of calls that remains to be made
getActive: return true if the clock is active
Examples
- Example 1: Flashs with a LED
- Example 2: Flashs and button
- Example 3: Flashs and on/off/a>
- Example 4: Bursts of 5 flashes
- Example 5: Bursts with on/off