Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Toggling Between Two buttons (http://www.chiefdelphi.com/forums/showthread.php?t=143098)

Ryan_Sciarabba 03-02-2016 15:14

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.

GreyingJay 03-02-2016 15:16

Re: Toggling Between Two buttons
 
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.

Arhowk 03-02-2016 15:40

Re: Toggling Between Two buttons
 
Code:

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

motor.set(motorSet)

python pseudocode

T3_1565 03-02-2016 15:58

Re: Toggling Between Two buttons
 
Quote:

Originally Posted by Arhowk (Post 1534535)
Code:

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

motor.set(motorSet)

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.

GreyingJay 03-02-2016 16:11

Re: Toggling Between Two buttons
 
Quote:

Originally Posted by T3_1565 (Post 1534542)
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.

Ryan_Sciarabba 04-02-2016 15:41

Re: Toggling Between Two buttons
 
I'm working in FRC Labview 2015.

BitTwiddler 04-02-2016 16:06

Re: Toggling Between Two buttons
 
1 Attachment(s)
Quote:

Originally Posted by Ryan_Sciarabba (Post 1535076)
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.

Dave

Alan Anderson 06-02-2016 22:58

Re: Toggling Between Two buttons
 
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.


All times are GMT -5. The time now is 14:55.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi