Toggling Between Two buttons

I need some code that will allow me to hit a button on a controller, stay on and will rotate a motor on direction. Then be able to hit a different button on the controller and have it turn the first button off, turn the second button on and rotate the motor the other direction.

What language are you working in?

Hint: variables can be used to track the current state of “stuff”, and you can use if statements or switch/case statements to do “stuff” based on the current value of a variable.

if button.pressed():
    if !buttonWasPressed:
         buttonWasPressed = True
         motorSet = 1 - motorSet
         buttonWasPressed = False


python pseudocode

That doesn’t seem like what he is asking for.

I’m not a programmer at all but I think a variable is the correct way to deal with your request.

if Button A is pressed then set variable “X” to 1.
if Button B is pressed then set variable “X” to 2.
if “X” = 1 then Motor runs one way
if “X” = 2 then motor runs the other way

Again. Not a programmer. Just how your request sounds in my head.

This is correct.

Note that as it stands once one of these two buttons is pressed and the motor turns on, there is no way to turn it off again.

I’m working in FRC Labview 2015.

I think this vi comes close to what you are looking for. Let me know if you need more details on how it works.


S-R (16 KB)

S-R (16 KB)

In LabVIEW, what you want to do is pretty easy. You only want to change the value being sent to the motor controller when a button is pressed, right? You want the motor to keep turning in whatever direction it was turning when you let go of the button, right?

Use a Case block wired to the button value. In the True case, set the motor to whatever value you want. Leave the False case empty. Use another similar Case block for the other button. This will do what you asked for. You will want to avoid pressing both buttons at the same time, because what the motor does might not be predictable.

It won’t give you a way to turn off the motor, though. This might be okay, or you might need to rethink your requirements.