Question About Competition Program

I am the programmer for team 9185 and I’ve found the sample program for the code chooser for Vex LCD. I put it into my program in the pre-auton and auton parts, but it didn’t let me drive the robot anymore. I troubleshooted, and found out that if I take out the pre-auton part, it lets me drive the robot. I am not sure how to implement the code chooser program into competition programs. Can anyone show me a code choosing program for competition?


#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl1,  Limit,          sensorTouch)
#pragma config(Sensor, I2C_1,  Lift1,          sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  Lift4,          sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port1,           RightFront,    tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor,  port2,           RightBack,     tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port3,           Lift1,         tmotorServoContinuousRotation, openLoop, reversed, encoderPort, I2C_1)
#pragma config(Motor,  port4,           Lift4,         tmotorServoContinuousRotation, openLoop,encoderPort, I2C_2)
#pragma config(Motor,  port5,           Intake1,       tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port6,           Intake2,       tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           Claw,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           LeftBack,      tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port9,           LeftFront,     tmotorVex393_MC29, openLoop, reversed)


#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!

const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
//Declare count variable to keep track of our choice
int count = 0;

//Wait for Press--------------------------------------------------
void waitForPress()
{
	while(nLCDButtons == 0){}
	wait1Msec(5);
}
//----------------------------------------------------------------

//Wait for Release------------------------------------------------
void waitForRelease()
{
	while(nLCDButtons != 0){}
	wait1Msec(5);
}
//----------------------------------------------------------------


void pre_auton()
{
	// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
	// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
	bStopTasksBetweenModes = false;

	// All activities that occur before the competition starts
	// Example: clearing encoders, setting servo positions, ...



		//------------- 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, "Red Loader");
			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, "Red NotLoader");
			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, "Blue Loader");
			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, "Blue Notloader");
			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 ---------------------
	
}

task autonomous()
{
	//------------- 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, "Red Loader");
		displayLCDCenteredString(1, "is running!");
		//Red Program Loader Side
		break;
	case 1:
		//If count = 1, run the code correspoinding with choice 2
		displayLCDCenteredString(0, "Red Notloader");
		displayLCDCenteredString(1, "is running!");
		//Red Program Not Loader Side
		break;
	case 2:
		//If count = 2, run the code correspoinding with choice 3
		displayLCDCenteredString(0, "Blue Loader");
		displayLCDCenteredString(1, "is running!");
		//Blue Program Loader Side
		break;
	case 3:
		//If count = 3, run the code correspoinding with choice 4
		displayLCDCenteredString(0, "Blue Notloader");
		displayLCDCenteredString(1, "is running!");
		//Blue Program Not Loader Side
		break;
	default:
		displayLCDCenteredString(0, "No valid choice");
		displayLCDCenteredString(1, "was made!");
		break;
	}
	//------------- End of Robot Movement Code -----------------------
}

task usercontrol()
{
	int joy_1;            // will hold the X value of the analog stick (choices below)
	int joy_2;            // will hold the Y value of the analog stick (choices below)
	int joy_3;            // will hold the X value of the analog stick (choices below)
	int joy_4;            // will hold the Y value of the analog stick (choices below)
	int joy_total;        // total amount of joy_1 & joy_2 & joy_4 for motor speed control
	int threshold = 10;   // helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)
	int LiftDif;
	int LiftDifSpeed;

	//Clear the encoders associated with the lift motors
	nMotorEncoder[Lift1] = 0;
	nMotorEncoder[Lift4] = 0;
	
	while (true)
	{
		LiftDif=nMotorEncoder[Lift1]-nMotorEncoder[Lift4];					// Lift1 - Lift4
		//Remote Control
		//Motor Control, Channels 1,2,4 for RightFront,RightBack,LeftBack,LeftFront
		if(abs(vexRT[Ch1]) > threshold)
		{
			joy_1 = vexRT[Ch1];
		}
		else
		{
			joy_1 = 0;
		}

		if(abs(vexRT[Ch2]) > threshold)
		{
			joy_2 = vexRT[Ch2];
		}
		else
		{
			joy_2 = 0;
		}

		if(abs(vexRT[Ch3]) > threshold)
		{
			joy_3 = vexRT[Ch3];
		}
		else
		{
			joy_3 = 0;
		}

		if(abs(vexRT[Ch4]) > threshold)
		{
			joy_4 = vexRT[Ch4];
		}
		else
		{
			joy_4 = 0;
		}

		//When the total output is more than 127, joy_total is increased to fix balance.
		//If it is less, joy_total is 127.
		if( abs(joy_1) + abs(joy_2) + abs(joy_4) > 127)
		{
			joy_total = abs(joy_1) + abs(joy_2) + abs(joy_4);
		}
		else
		{
			joy_total=127;
		}

		//Motor Speed Setup
		//When joy_total is 127, 127/127 = 1
		motor[RightFront] = (-joy_4 + joy_3 - joy_1)*127/joy_total; // V(x)*cos(A)+V(y)*sin(A)+wR     A=motor angle
		motor[RightBack]  = ( joy_4 + joy_3 - joy_1)*127/joy_total; //                                R=distance from center
		motor[LeftBack]   = ( joy_4 - joy_3 - joy_1)*127/joy_total; //                                w=angle/sec
		motor[LeftFront]  = (-joy_4 - joy_3 - joy_1)*127/joy_total;

		if(LiftDif>100)
		{
			LiftDifSpeed=1;
		}
		else if(LiftDif<-100)
		{
			LiftDifSpeed=-1;
		}
		else
		{
			LiftDifSpeed=0;
		}
		
			if(vexRT[Btn6U] == 1)
			{
				motor[Lift1]=100-LiftDifSpeed*27;						//Change Speed
				motor[Lift4]=100+LiftDifSpeed*27;
			}
			else if(vexRT[Btn6D] == 1)
			{
				motor[Lift1]=-100-LiftDifSpeed*27;
				motor[Lift4]=-100+LiftDifSpeed*27;
			}
			else
			{
				motor[Lift1] = 10+vexRT[Btn8U]*10-vexRT[Btn8D]*10;				//Constant Power
				motor[Lift4] = 10+vexRT[Btn7U]*10-vexRT[Btn7D]*10;
			}
		//Intake Control
		if(vexRT[Btn5U] == 1)
		{
			motor[Intake1] = 127;
			motor[Intake2] = 127;
		}
		else if(vexRT[Btn5D] == 1)
		{
			motor[Intake1] = -127;
			motor[Intake2] = -127;
		}
		else
		{
			motor[Intake1] = 0;
			motor[Intake2] = 0;
		}

		if(vexRT[Btn7R] == 1)
		{
			motor[Claw] = 127;
		}
		else if(vexRT[Btn7L] == 1)
		{
			motor[Claw] = -127;
		}
		else
		{
			motor[Claw] = 0;
		}
	}
}

Your code seems to be waiting until the center LCD button get’s pressed. Try pressing it and try if driver control works.

That’s exactly the problem.

Some explanation of how to do this correctly here.
ROBOTC LCD autonomous selection

Thank you both. The robot drives now with the competition program on it.