Hi guys,
Many of us have needed to use the controller to do something while waiting on an other process...
There are many ways to do that and one of the most efficient is shown by Robin2 on the following example:
http://forum.arduino.cc/index.php?topic=223286.0
I took the time to implement it in a library:
It's very efficient because it uses no resources such as timers and you can set up many asynchronous processes.
To call a cyclic routine we just need to declare an instance of the class PseudoParallelProcessing referring to the subroutine it will cyclically call:
PseudoParallelProcessing multiTasker1(CyclicProcess);
Create the Subroutine with the cyclic process you want to execute:
void CyclicProcess()
{
Serial.println("Counter = " + String(iCounter));
}
And finally run it every cycle, it will determine if it is time to run the routine and if not it will just free the processor for the next task (The first parameter is the interval between execution scan and the second is the current time (both in ms):
multiTasker1.RunIt(500, iNow);
Check the Example to see how to manage multiple tasks each with it's own execution rate, it's very intuitive to use.
PseudoParallelProcessing.cpp (1.77 KB)
PseudoParallelProcessing.h (1.44 KB)
PseudoParallelProcessingExample.ino (1.76 KB)