Call:      Timer(unsigned long Time,int TimerNo) 

Input:    Time in mS, TimerNo 

Output:  boolean 

 

The function Timer is made for the following reason; with the use of the standard Arduino Delay function it is possible to wait a certain amount of time, but that would delay –hold up- the execution of the loop and that’s for the Finite state machine sketch, only useful for debug actions. The loop must keep on running. Instead of Delay, a Timer structure is made based on a pointer structure. New timers are added to the pointer chain and removed again when they expire. The timer chain is theoretical infinite. When calling this function the first time and TimerNo is not known in the timer structure, a new timer structure will be added to the timer chain. Every cycle the function is called, the current time is checked. When the defined time is expired, the function returns true for one cycle and is removed from the timer structure. In all other cases the function returns false. There is a function available in the serial monitor to check all timers present in the timer chain; TimerId, initial time and time-to-go are presented.

 

Example:

if (Timer(60000,TimISR)) 

  { 

  ... code ...