Go to Post So is it important to try? Without a doubt. Does it become frustrating to not win? Most certainly. Should you stop trying? Never! - Al Skierkiewicz [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi