Go to Post If they had kids, they would be a super-breed of robot builders and drivers, and would win dozens of awards per season. - smurfgirl [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 Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 30-10-2014, 09:48
samfruth's Avatar
samfruth samfruth is offline
Registered User
FRC #1710 (Ravonics Revolution)
Team Role: Driver
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Olathe, Kansas
Posts: 132
samfruth will become famous soon enough
Turning a button into a switch

I have worked with LabView for three years or so now but have recently joined an FTC team. We are using RobotC as the programming language on this team.
My question is, how can I turn a button into a switch? The functionality of this button would essentially cause the robot to enter a different mode. Even if you don't quite now how to do it in RobotC, I can use the fundamental idea and translate it.

Thanks!!

-Noob Programmer
  #2   Spotlight this post!  
Unread 30-10-2014, 10:16
Drakxii Drakxii is offline
Registered User
FRC #4131 (Iron Patriots)
Team Role: Mentor
 
Join Date: May 2014
Rookie Year: 2012
Location: United States
Posts: 120
Drakxii is just really niceDrakxii is just really niceDrakxii is just really niceDrakxii is just really niceDrakxii is just really nice
Re: Turning a button into a switch

Create a variable that holds the mode that robot is in. (IE 1 = tall mode, 2 = short mode, etc...) Then when you hit the button it would run a set if statements to check what mode it is in and switch that variable to the other value(s). Finally the rest of the code would look to that variable which would determine the mode it is in.
  #3   Spotlight this post!  
Unread 30-10-2014, 10:32
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,801
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Turning a button into a switch

You also need a check to keep from rapidly toggling while the button is held momentarily.
A check that requires releasing and pressing the button again for it to toggle.

e.g.,

Code:
if (button == true & button /= previous_button_state)  
         button_toggle = !button_toggle

previous_button_state = button

if (button_toggle == true)
         do something
else
         do nothing
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 30-10-2014 at 10:42.
  #4   Spotlight this post!  
Unread 02-11-2014, 01:56
tcjinaz tcjinaz is offline
Tim
FRC #3853
Team Role: Mentor
 
Join Date: May 2011
Rookie Year: 2011
Location: Arizona
Posts: 206
tcjinaz has a spectacular aura abouttcjinaz has a spectacular aura about
Re: Turning a button into a switch

One might want to wait longer than two cycles; the loop timing matters. The way kids play video games theses days, de-bouncing the drivers is important.
__________________
Software Mentor
3853 Pridetronics[

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 02:43.

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