|
Re: [FTC]: Toggle controls
The modulo ("%") function code will do what you want, but you really should look into state machines. The code should look more like:
int state=0;
while (true) {
... (add your getjoystick function here)
... (and any other code you have)
switch (state) {
case 0:
if(joy2Btn(1)) // if button one is pressed
{
// Move your server to the first position (aka state)
servo[Servo1] = 100;
state = 1;
}
break;
case 1:
if (joy2Btn(1) == 0) {
// if the button was released then we can wait for another
// button push
state = 2;
}
break;
case 2:
if(joy2Btn(1)) // if button one is pressed
{
// now move your servo to the other position (aka state)
servo[Servo1] = 0;
state = 3;
}
break;
case 3:
if (joy2Btn(1) == 0) {
// again, wait for the button to be released
// before we look for another push
state = 0;
}
break;
default:
state = 0;
break;
}
}
Hope this helps.
Paul Tan.
__________________
Paul C. Tan., P.Eng.
Coach - FTC Team 27 (now retired)
Coach - VRC Team 2027 (now retired)
Past Mentor - FRC Teams 188, 610, 1009, 2634
|