|
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.
|