View Single Post
  #5   Spotlight this post!  
Unread 05-09-2011, 05:17 PM
TofuRama TofuRama is offline
01000110 01010010 01000011
AKA: Matt
FRC #2484 (Team Implosion)
Team Role: Programmer
 
Join Date: Apr 2011
Rookie Year: 2009
Location: Woods Cross Utah
Posts: 17
TofuRama is an unknown quantity at this point
Re: Wait(); function

I looked at your code and there are a few issues with it. One is that the timer will never get past 1. This is because it sets it to 0 within the if statement but also increments it only in the if statement as well. Another issue is that you're only checking to see if the motors should stop in the if statement. You can try this code and see if it should work:

//declare the timer as static to keep the value from the last loop
static int timer = 0;

//check if the trigger was pushed
if(Thirdstick.GetTrigger())
{
//if so, start the motors and reset the timer
timer = 0;
motor->Set(1.0);
}
//increment the timer
timer++;
if(timer >= 1000)
{
//stop the motors
motor->Set(0.0);
}

Also, as for an actual timer there is a timer class. Below is the syntax to use it:

//create a new timer class
Timer *timer = new Timer();
//start the timer
timer->Start();
//reset the timer, call this anytime that you want the timer to be set at zero
timer->Reset();

I hope this helps!
Reply With Quote