Go to Post EVERYTHING in life is politics. - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-03-2016, 03:14 PM
Ryan_Sciarabba Ryan_Sciarabba is offline
Registered User
FRC #5254
 
Join Date: Jan 2016
Location: New York
Posts: 3
Ryan_Sciarabba is an unknown quantity at this point
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.
  #2   Spotlight this post!  
Unread 02-03-2016, 03:16 PM
GreyingJay GreyingJay is online now
Robonut
AKA: Mr. Lam
FRC #2706 (Merge Robotics)
Team Role: Mentor
 
Join Date: Mar 2015
Rookie Year: 2015
Location: Ottawa, Canada
Posts: 738
GreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond repute
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.
  #3   Spotlight this post!  
Unread 02-03-2016, 03:40 PM
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Toggling Between Two buttons

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

motor.set(motorSet)
python pseudocode
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
  #4   Spotlight this post!  
Unread 02-03-2016, 03:58 PM
T3_1565 T3_1565 is offline
Registered User
AKA: Twitch Drive Designer
FRC #1360
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: Burlington, Ontario
Posts: 854
T3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant futureT3_1565 has a brilliant future
Send a message via MSN to T3_1565
Re: Toggling Between Two buttons

Quote:
Originally Posted by Arhowk View Post
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.
  #5   Spotlight this post!  
Unread 02-03-2016, 04:11 PM
GreyingJay GreyingJay is online now
Robonut
AKA: Mr. Lam
FRC #2706 (Merge Robotics)
Team Role: Mentor
 
Join Date: Mar 2015
Rookie Year: 2015
Location: Ottawa, Canada
Posts: 738
GreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond repute
Re: Toggling Between Two buttons

Quote:
Originally Posted by T3_1565 View Post
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.
  #6   Spotlight this post!  
Unread 02-04-2016, 03:41 PM
Ryan_Sciarabba Ryan_Sciarabba is offline
Registered User
FRC #5254
 
Join Date: Jan 2016
Location: New York
Posts: 3
Ryan_Sciarabba is an unknown quantity at this point
Re: Toggling Between Two buttons

I'm working in FRC Labview 2015.
  #7   Spotlight this post!  
Unread 02-04-2016, 04:06 PM
BitTwiddler's Avatar
BitTwiddler BitTwiddler is offline
electronics/programming mentor
AKA: Mr Tanguay
FRC #1726 (N.E.R.D.S.)
Team Role: Mentor
 
Join Date: Oct 2008
Rookie Year: 2006
Location: Sierra Vista, AZ
Posts: 240
BitTwiddler is on a distinguished road
Re: Toggling Between Two buttons

Quote:
Originally Posted by Ryan_Sciarabba View Post
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
Attached Files
File Type: vi S-R Latches.vi (16.0 KB, 10 views)
  #8   Spotlight this post!  
Unread 02-06-2016, 10:58 PM
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:21 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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