while(condition) {
line follow commands
}
while(true) {
read the joystick and respond
}
That way, when the first condition is met the first loop ends. Then the second loop starts and remains. You could get it to flip back and forth, too, such as turning off user control to restart the line follow by pressing a button:
while(true){
while(condition) {
line follow commands
}
while(condition) {
read the joystick and respond
}
}
I think I know what you are asking – [to press a button to follow a line and then press a button to cancel]
should look something like this
while(true){
bool followtrue = false;//boolean for the line follower, initialize so that if a button is not originally pressed it dose not cause an error
if(vexRT[Btn5U]){//will set the var to true
followtrue = true;
}
else if(vexRT[Btn5D]){//sets the var to false
followtrue = false;
}
if(followtrue){//if var is true run this code
//follow line
if(SensorValue[linesensor] > threshold){
//turn right or left
rightdrive(90);
leftdrive(40);
}
else if(SensorValue[linesensor] < threshold){
//turn opposite direction
rightdrive(40);
leftdrive(90);
}
else{//var is false
//usercontrol drive mode
//either start a new task for this or put all your driver code here
//I use methods so mine would look something like this...
arcade();
lift();
claw();
}
}