programming help

Today I was programming our antonymous and when I tried to download to our bot and an error came up it said something like competition duration wasn’t at the global level. If anyone has an idea what the problem is I would love it. Later I will post the coding.

here is our code there are some errors we just cant figure out i would love if someone could fix it
#pragma config(Motor, port3, Drive2, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port4, Drive3, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port5, Drive4, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port6, launchleft, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port7, launchright, tmotorVex393_MC29, openLoop, reversed, driveLeft)
#pragma config(Motor, port8, gate, tmotorServoStandard, openLoop, driveRight)
#pragma config(Motor, port9, leftintake, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, rightintake, tmotorVex393_HBridge, openLoop)
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include “Vex_Competition_Includes.c” //Main competition background code…do not modify!
/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////
void pre_auton()
{
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
//Wait for Press--------------------------------------------------
void waitForPress()
{
while(nLCDButtons == 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
//Wait for Release------------------------------------------------
void waitForRelease()
{
while(nLCDButtons != 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
task main()
{
//Declare count variable to keep track of our choice
int count = 0;
//------------- Beginning of User Interface Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Loop while center button is not pressed
while(nLCDButtons != centerButton)
{
//Switch case that allows the user to choose from 4 different options
switch(count){
case 0:
//Display first choice
displayLCDCenteredString(0, “Autonomous 1”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();
//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count = 3;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 1:
//Display second choice
displayLCDCenteredString(0, “Autonomous 2”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();
//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count–;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 2:
//Display third choice
displayLCDCenteredString(0, “Autonomous 3”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();
//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count–;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 3:
//Display fourth choice
displayLCDCenteredString(0, “Autonomous 4”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();
//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count–;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count = 0;
}
break;
default:
count = 0;
break;
}
}
//------------- End of User Interface Code ---------------------
//------------- Beginning of Robot Movement Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Switch Case that actually runs the user choice
switch(count){
case 0:
//If count = 0, run the code correspoinding with choice 1
displayLCDCenteredString(0, “Autonomous 1”);
displayLCDCenteredString(1, “is running!”);
wait1Msec(2000); // Robot waits for 2000 milliseconds
// Move forward at full power for 3 seconds
motor[Drive1] = 127; // Motor on port2 is run at full (127) power forward
motor[Drive2] = 127; // Motor on port3 is run at full (127) power forward
wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
break;
case 1:
//If count = 1, run the code correspoinding with choice 2
displayLCDCenteredString(0, “Autonomous 2”);
displayLCDCenteredString(1, “is running!”);
wait1Msec(2000); // Robot waits for 2000 milliseconds
// Move reverse at full power for 3 seconds
motor[Drive1] = -127; // Motor on port2 is run at full (-127) power reverse
motor[Drive2] = -127; // Motor on port3 is run at full (-127) power reverse
wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
break;
case 2:
//If count = 2, run the code correspoinding with choice 3
displayLCDCenteredString(0, “Autonomous 3”);
displayLCDCenteredString(1, “is running!”);
wait1Msec(2000); // Robot waits for 2000 milliseconds
//Turn right for 3 seconds
motor[Drive1] = -63; // Motor on port2 is run at half power reverse
motor[Drive2] = 63; // Motor on port3 is run at half power forward
wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
break;
case 3:
//If count = 3, run the code correspoinding with choice 4
displayLCDCenteredString(0, “Autonomous 4”);
displayLCDCenteredString(1, “is running!”);
wait1Msec(2000); // Robot waits for 2000 milliseconds
//Turn left for 3 seconds
motor[Drive1] = 63; // Motor on port2 is run at half power forward
motor[Drive2] = -63; // Motor on port3 is run at half power reverse
wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
break;
default:
displayLCDCenteredString(0, “No valid choice”);
displayLCDCenteredString(1, “was made!”);
break;
}
}
bStopTasksBetweenModes = true;

}
/////////////////////////////////////////////////////////////////////////////////////////
//
// Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////
task autonomous()
{
motor[port6] = 65.5;
motor[port7] = 65.5;
motor[port10] = 100;
motor[port9] = 100;
motor[port1] = -127;
wait(30); //Robot waits for 2000 milliseconds before executing program
SensorValue[rightencoder] = 0; //Set the encoder so that it starts counting at 0
while(SensorValue(rightencoder) < 1800) //While rightEncoder has counted less than 1800 counts
{
//Turn Left
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = -127;
motor[Drive4] = -127;
}
SensorValue[leftencoder] = 0; //Set the encoder so that it starts counting at 0
while(SensorValue(leftencoder) < 1800) //While leftEncoder has counted less than 1800 counts
{
//Turn Right
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = 127;
motor[Drive4] = 127;
}

while(SensorValue(sonarsensor) > 20 || SensorValue(sonarsensor) == -1) // Loop while robot’s Ultrasonic sensor is further than 20 inches away from an object
{ // || (or) it is ‘-1’. (-1 is the value returned when nothing is in it’s visable range)
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = 127;
motor[Drive4] = 127;

}
/////////////////////////////////////////////////////////////////////////////////////////
//
// User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////
task usercontrol()
{
// User control code here, inside the loop
while (1 == 1)
{
motor[Drive1] = (vexRT[Ch2]);
motor[Drive2] = (vexRT[Ch2]);
motor[Drive3] = (vexRT[Ch3]);
motor[Drive4] = (vexRT[Ch3]);
if(vexRT[Btn5UXmtr2] == 1)
{
motor[port6] = 65.5;
motor[port7] = 65.5;

}
else
{
motor[port6] = 0;
motor[port7] = 0;
}
if(vexRT[Btn6UXmtr2] == 1)
{
motor[port10] = 100;
motor[port9] = 100;
motor[port1] = -127;
}
else if(vexRT[Btn6DXmtr2] == 1)
{
motor[port10] = -127;
motor[port9] = -127;
motor[port1] = 127;
}
else
{
motor[port10] = 0;
motor[port9] = 0;
motor[port1] = 0;
}
if(vexRT[Btn6U] == 1)
{
setServo(port8, 0);
}
else
{
setServo(port8, 100);
}
}
}
}

It seems like you deleted the pre auton duration pragma
I don’t know the specific pragma but go to another empty comp template and look at the duration for pre auton and copy it back into this code which should fix your problems.

Use the freaking syntax highlighter, we spent years begging for it so the least you can do is actualy use it.

Two big issues with the code, it doesn’t really compile so any attempts to download would fail.

  1. You have a main task, that is not necessary when using the competition template, put all code into the autonomous or usercontrol tasks (or the pre_auton function).

  2. There are lots of other syntax errors.

I will try that and see its our teams first time trying to use a lcd screen.

OK I am getting really close but when i down load the sample program i get this error Error:Functions must be defined at main scope level if someone could tell me how to fix it i would love it. I have also re updated the program at the top with my new program that i am a lot closer to getting it done.

FIrstly, you cannot just copy and paste code from a sample program without any understanding of how it works and expect it to work in your code. There were functions and movement code in the pre-autonomous (hence your errors) as well as a task main. I don’t even know what you are intending to do with the LCD because of how you have your autonomous setup. This fixes any major errors (I don’t have a copy of RobotC to test it on) and sets your current autonomous to Autonomous 1 on the LCD Display. Although there a still a LOT of syntax errors you will have to fix up yourself. Can I recommend you take a look at this article, which goes over what each part of code does.
http://www.robotc.net/blog/2012/05/18/advanced-applications-with-the-vex-lcd/

Also, if you press the little code button in the top of the comment box. You can put the code in a nice code box which makes it easier to read as well as easy to copy and applies the syntax highlighting @Cody was talking about

#pragma config(Motor, port3, Drive2, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port4, Drive3, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port5, Drive4, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port6, launchleft,  tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port7, launchright, tmotorVex393_MC29, openLoop, reversed, driveLeft)
#pragma config(Motor, port8, gate, tmotorServoStandard, openLoop, driveRight)
#pragma config(Motor, port9, leftintake,  tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, rightintake, tmotorVex393_HBridge, openLoop)
#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c" //Main competition background code...do  not modify!

void waitForPress()
{
    while(nLCDButtons == 0){}
    wait1Msec(5);
}

void waitForRelease() 
{
    while(nLCDButtons != 0){}
    wait1Msec(5);
}

void pre_auton()
{
    const short leftButton = 1;
    const short centerButton = 2;
    const short rightButton = 4;

    //Declare count variable to keep track of our choice
    int count = 0;
    //------------- Beginning of User Interface Code ---------------
    //Clear LCD
    clearLCDLine(0);
    clearLCDLine(1);
    //Loop while center button is not pressed
    while(nLCDButtons != centerButton)

    //Switch case that allows the user to choose from 4 different options
    switch(count) {

//===============

    case 0:
    //Display first choice
    displayLCDCenteredString(0, "Autonomous 1");
    displayLCDCenteredString(1, "< Enter >");
    waitForPress();

    //Increment or decrement "count" based on button press
    if(nLCDButtons == leftButton)
    {
        waitForRelease();
        count = 3;
    }
    else if(nLCDButtons == rightButton)
    {
        waitForRelease();
        count++;
    }
    break;

//===============

    case 1:
    //Display second choice
    displayLCDCenteredString(0, "Autonomous 2");
    displayLCDCenteredString(1, "< Enter >");
    waitForPress();
    //Increment or decrement "count" based on button press
    if(nLCDButtons == leftButton)
    {
    waitForRelease();
    count--;
    }
    else if(nLCDButtons == rightButton)
    {
    waitForRelease();
    count++;
    }
    break;

//===============

    case 2:
    //Display third choice
    displayLCDCenteredString(0, "Autonomous 3");
    displayLCDCenteredString(1, "< Enter >");
    waitForPress();
    //Increment or decrement "count" based on button press
    if(nLCDButtons == leftButton)
    {
    waitForRelease();
    count--;
    }
    else if(nLCDButtons == rightButton)
    {
    waitForRelease();
    count++;
    }
    break;

//===============

    case 3:
    //Display fourth choice
    displayLCDCenteredString(0, "Autonomous 4");
    displayLCDCenteredString(1, "< Enter >");
    waitForPress();
    //Increment or decrement "count" based on button press
    if(nLCDButtons == leftButton)
    {
    waitForRelease();
    count--;
    }
    else if(nLCDButtons == rightButton)
    {
    waitForRelease();
    count = 0;
    }
    break;

//===============

    default:
    count = 0;
    break;
    }
}
//------------- End of User Interface Code ---------------------



}
/////////////////////////////////////////////////////////////////////////////////////////
//
// Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////
task autonomous()
{

    bStopTasksBetweenModes = true;

    //Clear LCD
    clearLCDLine(0);
    clearLCDLine(1);

    //Switch Case that actually runs the user choice
    switch(count){

//===============

    case 0:

        //If count = 1, run the code correspoinding with choice 2
        displayLCDCenteredString(0, "Autonomous 1");
        displayLCDCenteredString(1, "is running!");

        motor[port6] = 65.5;
        motor[port7] = 65.5;
        motor[port10] = 100;
        motor[port9] = 100;
        motor[port1] = -127;

        wait(30); //Robot waits for 2000 milliseconds before executing program

        SensorValue[rightencoder] = 0; //Set the encoder so that it starts counting at 0
        while(SensorValue(rightencoder) < 1800) //While rightEncoder has counted less than 1800 counts
        {
            //Turn Left
            motor[Drive1] = 127;
            motor[Drive2] = 127;
            motor[Drive3] = -127;
            motor[Drive4] = -127;
        }

        SensorValue[leftencoder] = 0; //Set the encoder so that it starts counting at 0
        while(SensorValue(leftencoder) < 1800)  //While leftEncoder has counted less than 1800 counts
        {
            //Turn Right
            motor[Drive1] = 127;
            motor[Drive2] = 127;
            motor[Drive3] = 127;
            motor[Drive4] = 127;
        }

        while(SensorValue(sonarsensor) > 20 || SensorValue(sonarsensor) == -1) // Loop while robot's Ultrasonic sensor is further than 20 inches away from an object
        { // || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range)
            motor[Drive1] = 127;
            motor[Drive2] = 127;
            motor[Drive3] = 127;
            motor[Drive4] = 127;
        break;

//===============

    case 1:

        //If count = 1, run the code correspoinding with choice 2
        displayLCDCenteredString(0, "Autonomous 2");
        displayLCDCenteredString(1, "is running!");
        wait1Msec(2000); // Robot waits for 2000 milliseconds
        // Move reverse at full power for 3 seconds
        motor[Drive1] = -127; // Motor on port2 is run at full (-127) power reverse
        motor[Drive2] = -127; // Motor on port3 is run at full (-127) power reverse
        wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
        break;

//===============

    case 2:

        //If count = 2, run the code correspoinding with choice 3
        displayLCDCenteredString(0, "Autonomous 3");
        displayLCDCenteredString(1, "is running!");
        wait1Msec(2000); // Robot waits for 2000 milliseconds
        //Turn right for 3 seconds
        motor[Drive1] = -63; // Motor on port2 is run at half power reverse
        motor[Drive2] = 63; // Motor on port3 is run at half power forward
        wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
        break;

//===============

    case 3:

        //If count = 3, run the code correspoinding with choice 4
        displayLCDCenteredString(0, "Autonomous 4");
        displayLCDCenteredString(1, "is running!");
        wait1Msec(2000); // Robot waits for 2000 milliseconds
        //Turn left for 3 seconds
        motor[Drive1] = 63; // Motor on port2 is run at half power forward
        motor[Drive2] = -63; // Motor on port3 is run at half power reverse
        wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
        break;

//===============

    default:
        displayLCDCenteredString(0, "No valid choice");
        displayLCDCenteredString(1, "was made!");
        break;

}
/////////////////////////////////////////////////////////////////////////////////////////
//
// User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////
task usercontrol()
{
    // User control code here, inside the loop
    while (true)
    {
        motor[Drive1] = (vexRT[Ch2]);
        motor[Drive2] = (vexRT[Ch2]);
        motor[Drive3] = (vexRT[Ch3]);
        motor[Drive4] = (vexRT[Ch3]);

        if(vexRT[Btn5UXmtr2] == 1)
        {
            motor[port6] = 65.5;
            motor[port7] = 65.5;
        }
        else
        {
            motor[port6] = 0;
            motor[port7] = 0;
        }

        if(vexRT[Btn6UXmtr2] == 1)
        {
            motor[port10] = 100;
            motor[port9] = 100;
            motor[port1] = -127;
        }
        else if(vexRT[Btn6DXmtr2] == 1)
        {
            motor[port10] = -127;
            motor[port9] = -127;
            motor[port1] = 127;
        }
        else
        {
            motor[port10] = 0;
            motor[port9] = 0;
            motor[port1] = 0;
        }

        if(vexRT[Btn6U] == 1)
        {
            setServo(port8, 0);
        }
        else
        {
            setServo(port8, 100);
        }
    }
}

Ok so I am really sorry for struggling with our program I have it down to one error please help

#pragma config(Sensor, dgtl1, leftencoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, rightencoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, sonarsensor, sensorSONAR_inch)
#pragma config(Motor, port1, BackIntake, tmotorVex393_HBridge, openLoop, driveRight)
#pragma config(Motor, port2, Drive1, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port3, Drive2, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port4, Drive3, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port5, Drive4, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port6, launchleft, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port7, launchright, tmotorVex393_MC29, openLoop, reversed, driveLeft)
#pragma config(Motor, port8, gate, tmotorServoStandard, openLoop)
#pragma config(Motor, port9, leftintake, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, rightintake, tmotorVex393_HBridge, openLoop)
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include “Vex_Competition_Includes.c” //Main competition background code…do not modify!
/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////
void waitForPress()
{
while(nLCDButtons == 0){}
wait1Msec(5);
}
void waitForRelease()
{
while(nLCDButtons != 0){}
wait1Msec(5);
}
void pre_auton()
{
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
//Declare count variable to keep track of our choice
int count = 0;
//------------- Beginning of User Interface Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Loop while center button is not pressed
while(nLCDButtons != centerButton)
//Switch case that allows the user to choose from 4 different options
switch(count)
{
//===============
case 0:
//Display first choice
displayLCDCenteredString(0, “Autonomous 1”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();

//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count = 3;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
//===============
case 1:
//Display second choice
displayLCDCenteredString(0, “Autonomous 2”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();
//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count–;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
//===============
case 2:
//Display third choice
displayLCDCenteredString(0, “Autonomous 3”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();
//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count–;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
//===============
case 3:
//Display fourth choice
displayLCDCenteredString(0, “Autonomous 4”);
displayLCDCenteredString(1, “< Enter >”);
waitForPress();
//Increment or decrement “count” based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count–;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count = 0;
}
break;
//===============
default:
count = 0;
break;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////
task autonomous()
{
bStopTasksBetweenModes = true;
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Switch Case that actually runs the user choice
int count = 0;
switch(count){
//===============
case 1:
//If count = 1, run the code correspoinding with choice 2
displayLCDCenteredString(0, “Autonomous 1”);
displayLCDCenteredString(1, “is running!”);
motor[port10] = 100;
motor[port9] = 100;
motor[port1] = -127;
wait(.1);
SensorValue[rightencoder] = 0; //Set the encoder so that it starts counting at 0
while(SensorValue(rightencoder) < 2800) //While rightEncoder has counted less than 1800 counts
{
//drive backward
motor[Drive1] = -127;
motor[Drive2] = -127;
motor[Drive3] = -127;
motor[Drive4] = -127;
wait(.1);
}
//Set the encoder so that it starts counting at 0
SensorValue[rightencoder] = 0;
while(SensorValue(rightencoder) < -600) //While leftEncoder has counted less than 1800 counts
{
//Turn Right
pointTurn(right,127);
wait(1);

//motor[Drive1] = -127;
// motor[Drive2] = -127;
//motor[Drive3] = 127;
// motor[Drive4] = 127;
}
while(SensorValue(sonarsensor) > 5 || SensorValue(sonarsensor) == -1) // Loop while robot’s Ultrasonic sensor is further than 20 inches away from an object
// || (or) it is ‘-1’. (-1 is the value returned when nothing is in it’s visable range)
{
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = 127;
motor[Drive4] = 127;
break;
//===============
switch(2){
case (1):
//If count = 1, run the code correspoinding with choice 2
displayLCDCenteredString(0, “Autonomous 2”);
displayLCDCenteredString(1, “is running!”);
wait1Msec(2000); // Robot waits for 2000 milliseconds

// Move forward at full power for 3 seconds
motor[port6] = 65.5;
motor[port7] = 65.5;
motor[port10] = 100;
motor[port9] = 100;
motor[port1] = -127;
wait(30); //Robot waits for 2000 milliseconds before executing program

SensorValue[rightencoder] = 0; //Set the encoder so that it starts counting at 0

while(SensorValue(rightencoder) < 1800) //While rightEncoder has counted less than 1800 counts
{
//Turn Left
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = -127;
motor[Drive4] = -127;
}

SensorValue[leftencoder] = 0; //Set the encoder so that it starts counting at 0

while(SensorValue(leftencoder) < 1800) //While leftEncoder has counted less than 1800 counts
{
//Turn Right
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = -127;
motor[Drive4] = -127;
}

while(SensorValue(sonarsensor) > 20 || SensorValue(sonarsensor) == -1) // Loop while robot’s Ultrasonic sensor is further than 20 inches away from an object
{ // || (or) it is ‘-1’. (-1 is the value returned when nothing is in it’s visable range)
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = 127;
motor[Drive4] = 127;
wait(60); // Robot runs previous code for 60 seconds before moving on
break;
switch(3){
case 2:
//If count = 2, run the code correspoinding with choice 3
displayLCDCenteredString(0, “Autonomous 3”);
displayLCDCenteredString(1, “is running!”);
wait1Msec(2000); // Robot waits for 2000 milliseconds

//Turn right for 3seconds
motor[Drive2] = -63; // Motor on port2 is run at half power reverse
motor[Drive4] = 63; // Motor on port3 is run at half power forward
wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
break;
switch(4){
case 3:
//If count = 3, run the code correspoinding with choice 4
displayLCDCenteredString(0, “Autonomous 4”);
displayLCDCenteredString(1, “is running!”);
wait1Msec(2000); // Robot waits for 2000 milliseconds
motor[Drive2] = -63; // Motor on port2 is run at half power reverse
motor[Drive4] = 63; // Motor on port3 is run at half power forward
wait1Msec(2000);
break;
default:
displayLCDCenteredString(0, “No valid choice”);
displayLCDCenteredString(1, “was made!”);
break;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
while (1==1)
{
motor[Drive1] = (vexRT[Ch2]);
motor[Drive2] = (vexRT[Ch2]);
motor[Drive3] = (vexRT[Ch3]);
motor[Drive4] = (vexRT[Ch3]);
}
if(vexRT[Btn5UXmtr2] == 1)
{
motor[port6] = 88; //65.5
motor[port7] = 88;
}
else
{
motor[port6] = 0;
motor[port7] = 0;
}

if(vexRT[Btn6UXmtr2] == 1)
{
motor[port10] = 90;
motor[port9] = 90;
motor[port1] = -127;
}
else if(vexRT[Btn6DXmtr2] == 1)
{
motor[port10] = -127;
motor[port9] = -127;
motor[port1] = 127;
}
else
{
motor[port10] = 0;
motor[port9] = 0;
motor[port1] = 0;
}

if(vexRT[Btn6U] == 1)
{
setServo(port8, -5);
}
else
{
setServo(port8, 105);
}
}
}
}
}