Software Timer Library

Thursday October 1, 2009

The first thing that bothered me with Arduino was the 'delay()' function. Delay seemed like an innapropriate way to deal with time as it affects the entire microcontroller and everything you're doing at the same time. This makes multitasking difficult: it's painful to control multiple elements/components, especially if you want them to do actions at irregular intervals.

To counter this problem, I programmed my own (first!) Arduino Library: a Software Timer. The software timer is an "alternative" to the delay function. Instead delaying everything, it allows you to call multiple functions at different interval. For example, this line:

timer.addCallback( 123 , myFunction, true );

Asks the timer to call the "void myFunction()" function every 123 millisecond. The line:

timer.addCallback( 211 , myFunction2, false );

Asks the timer to call 'myFunction2' only once in 211ms.


You can download the library with two examples here. (MIT License). Please note that it's still in beta version. For questions / Comments : edouardlb[æ}gmail.com.

You can see the library in action here (and in pretty much all of my sketches from now on)