Thread: Program Delay
View Single Post
  #5   Spotlight this post!  
Unread 02-10-2010, 09:25 AM
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Program Delay

Rikard, if I'm understanding your original post, you want to perform two actions with a single input, with the first action occurring immediately and the second occurring a second later. Instead using a timer (which would force you to continuoulsy check to see if a second has elapsed), you could use a Notifier class.

To use the Notifier class, you first create a function you want called after your elapsed time period (i.e. a function that would activate the piston in your case). The function takes a void pointer. You could use this by passing in a pointer to the solonoid you want to actuate, for example, and cast it back to a Solonoid pointer in the function.

Now to use the notifier class, when you construct it, give it the name of the function you want called as the TimerEventHandler argument and the pointer you want to pass to the function as the param argument. Then, when the user presses the button (or whatever your input is), call Notifier::StartSingle with the delay in seconds as the argument. In that amount of time, your function will automatically be called with the parameter you provided it.

I know this is kind of advanced programming, and if you're confused, feel free to PM me, but I think it would be the best way to do it. Unlike a timer, the Notifier class will automatically call your function in the specified amount of time without you having to worry about it any more.
__________________
Reply With Quote