Using the push button as a toggle.
robofan301
Posts: 4
I am using the homework help board to make a car that will drive forward, using continuous servos.
Since the HHB does not have an on off switch, I decided to try to get it to read a pushbutton, connected to a port (Port 2).
I can program the logic if IN2 =1, then stop motors. But since the button is spring loaded, as soon as I release the button, it will read zero and the motors will start up again.
What I'm trying to accomplish is to have the motors toggle. If I press the button once, the motors stop, if I press it again the motors start up again.
Can anyone give me a clue, as to how to work this type of logic in?
Someone who programs in Java told me to use a Boolean, but it appears that PBasic doesn't have this declaration?
What's my best move?
Thanks
Since the HHB does not have an on off switch, I decided to try to get it to read a pushbutton, connected to a port (Port 2).
I can program the logic if IN2 =1, then stop motors. But since the button is spring loaded, as soon as I release the button, it will read zero and the motors will start up again.
What I'm trying to accomplish is to have the motors toggle. If I press the button once, the motors stop, if I press it again the motors start up again.
Can anyone give me a clue, as to how to work this type of logic in?
Someone who programs in Java told me to use a Boolean, but it appears that PBasic doesn't have this declaration?
What's my best move?
Thanks
Comments
Solution is simple but there are a number of different ways to do the nuts and bolts part depending on your application.
Then I just incremented it by 1 every time the button was pressed.
Thanks Again.