How we would do that type of thing would be like this:
Code:
// in .h:
int led_state;
int pled_state;
double starttime;
// in .cpp
void LED_FLASHER::Init()
{
starttime = clock.Now();
}
void LED_FLASHER::Run()
{
switch(led_state)
{
case RED:
// Output Red
if((clock.Now - starttime)>TIME_TO_SWITCH)
{
starttime = clock.Now;
led_state = NEXT_COLOR;
}
break;
// ect.
}
pled_state = led_state;
}
Instead of using the "commands" (which is more of a Java type thing) we actually program our classes ourselves, it requires quite a bit more setup, but that means that we can have more control.
The idea is that you have full control over what runs every iteration, and the entire code runs each iteration. So maybe you only call LED_FLASHER.Run() every time (clock.Now()%5) == 0 (every five miliseconds), but you have full control over what is going on.