This is basically a set of timers and a very simple round-robin, run-to-completion scheduler. The scheduler runs off the millis() counter so all delays are in milliseconds.
Each task has 4 states:
In your program you need to set up a task block array, where each entry is the starting parameters for a task. Here is an example of what should be at the top of your sketch. The enumeration and NUM_TASKS are optional, if you just want to use the actual numbers.
// Task list where each line matches a line in the task block
enum
{
LED_BLINK_TASK = 0,
HELLO_WORLD_TASK
};
// The task block with starting values
TaskBlock taskBlock[] =
{
// Entry Point State Starting Count
{&ledBlinkTask, TASK_RUN, 0}, // LED_BLINK_TASK
{&helloWorldTask, TASK_RUN, 0} // HELLO_WORLD_TASK
};
// The number of tasks (automatically calculated
#define NUM_TASKS (sizeof(taskBlock)/sizeof(TaskBlock))
Then in your setup():
setup()
{
// put other setup stuff here
void TS.initialize(taskBlock, NUM_TASKS);
}
loop()
{
TS.run();
}