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.
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.
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.,
if (button == true & button /= previous_button_state)
button_toggle = !button_toggle
previous_button_state = button
if (button_toggle == true)
do something
else
do nothing
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.