Go to Post Sometimes our greatest failures lay the foundations for our greatest success. - =Martin=Taylor= [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

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-28-2013, 12:18 AM
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 : 07-28-2013 at 12:24 AM. Reason: Clarification
Reply With Quote
Reply


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 09:25 AM.

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