View Single Post
  #14   Spotlight this post!  
Unread 10-02-2009, 17:21
ptan ptan is offline
Paul C. Tan., P.Eng.
AKA: Paul Tan
no team (Bolt Action)
Team Role: Mentor
 
Join Date: Dec 2005
Rookie Year: 2000
Location: Toronto
Posts: 61
ptan is a splendid one to beholdptan is a splendid one to beholdptan is a splendid one to beholdptan is a splendid one to beholdptan is a splendid one to beholdptan is a splendid one to behold
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
Reply With Quote