View Single Post
  #12   Spotlight this post!  
Unread 28-07-2013, 00:18
Billy_B Billy_B is offline
Registered User
FRC #2704 (Order 2 Chaos)
Team Role: Programmer
 
Join Date: Jul 2013
Rookie Year: 2010
Location: United States
Posts: 6
Billy_B is an unknown quantity at this point
Re: Switching to Iterative

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.

Last edited by Billy_B : 28-07-2013 at 00:24. Reason: Clarification
Reply With Quote