|
Re: [FTC]: Toggle controls
OK. So what you want is that when u press a button, let's assume button 1, then the servo moves to one position. if you press another button, the servo moves to an original position.
So, the code has is a tad bit more complex.
int sum = 2;
if(joy2Btn(1)) // if button one is pressed
{
sum = sum +1;
}
int calcremainder = sum % 2; // This line calculates the remainder of sum/2.
if (calcremainder = 0)
{
servo[Servo1] = 100;
}
else
{
servo[Servo1] = 0;
}
So the code above basically does this. Each time you hit the button, the program counts it. I know there's an official counter in the program, but i'm ghetto like this.
Then, it takes the number of times the button has been hit, and it divides by 2. So, then the value can either be 0 or 1. So each time you hit the button, the value switches between 0 and 1, so when the value is 0, you have a position, when it is 1 you have a position.
That's the logic.
There might be a better way, but this is one possibly option.
__________________
1261: 2007-2012
1648: 2013-2014
5283: 2015
|