![]() |
How to create an On/Off button?
While reviewing our shooter code, I figured that the ability to be able to toggle our shooter wheels on/off would be a nice feature to have. However, no matter how hard I tried, I simply could not figure out a way to do this.
The only method that I was able to call upon was just joystickButton.get() since we are using Iterative robot this year. If it is possible to create an On/Off button, how would it be done? |
Re: How to create an On/Off button?
An On/Off button on the dashboard or on your joystick?
|
Re: How to create an On/Off button?
On the joystick. I would prefer a more physical button. :)
|
Re: How to create an On/Off button?
The easiest way would be to save the state as on or off in a boolean or byte variable and then switch it every time the button is pressed.
Pseudo-Code: Code:
if joystick button pressed then |
Re: How to create an On/Off button?
That won't work since teleop loops every 20ms, which means one press will equal a lot of Joystick.get()'s.
|
Re: How to create an On/Off button?
Use the Timer to limit how quickly you can toggle.
Code:
double interim = 2; //can only toggle every 2 seconds |
Re: How to create an On/Off button?
Code:
button1 = GetButton(button1); |
Re: How to create an On/Off button?
Quote:
I assume that if you wanted to start with the motors running, I would initialize toggle as true? |
Re: How to create an On/Off button?
Quote:
|
Re: How to create an On/Off button?
Quote:
|
Re: How to create an On/Off button?
This is code that I wrote and use. Just make all of your buttons AdvancedButton and call
button#.togglePressed(yourCommand); some variables are protected so that they cant be accessed but u can still extend the class and make your own addition code |
| All times are GMT -5. The time now is 09:52. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi