View Single Post
  #3   Spotlight this post!  
Unread 10-02-2015, 09:33
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,574
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Toggling Buttons

I'm unsure what you meant this to do, but it looks like you're trying to implement a 4-state machine with one button. If so, this will not achieve it - once isPressedPiston1 is set to true, it will never toggle again.

In any case, assuming that switchSol1 and isPressedPiston1 are persistent variables after isPressedPiston1 is set true, every time this routine is entered and button 3 is pressed, switchSol1 will toggle. The problem is likely that this routine is called rather quickly, in a loop. If so, this would cause the state of switchSol1 (and therefore sol1 and sol2) to twitch. Depending on your programming model, you can either use a whenPressed() callback to just call this one time when the button is pressed, or include a timeout. That is, when the state is toggled, set a time to wait (perhaps 300 milliseconds to start), and exit this routine immediately if it is called and you have not reached the timeout yet.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote