I am wondering if I can start a user control code area with my lcd display as opposed to having to have a competition switch. Here is my code:
#pragma config(Sensor, dgtl1, dgtl, sensorLEDtoVCC)
#pragma config(Motor, port2, lfwAMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, lfwBMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, rfwAMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, rfwBMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, iMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, lwMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, rwMotor, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
int count = 0;
//Wait for Press--------------------------------------------------
void waitForPress()
{
while(nLCDButtons == 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
//Wait for Release------------------------------------------------
void waitForRelease()
{
while(nLCDButtons != 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
void pre_auton()
{
bLCDBacklight = true;
bStopTasksBetweenModes = true;
SensorValue[dgtl1] = 1;
//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, "Blue Tile");
displayLCDCenteredString(1, "< Select >");
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 Tile");
displayLCDCenteredString(1, "< Select >");
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, "Test Blue");
displayLCDCenteredString(1, "< Select >");
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 ---------------------
}
}
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, "Autonomous 1");
displayLCDCenteredString(1, "is running!");
wait1Msec(2000); // Robot waits for 2000 milliseconds
// Move forward at full power for 3 seconds
startTask(usercontrol);
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
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
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
SensorValue[dgtl1] = 1;
//Turn left for 3 seconds
break;
default:
displayLCDCenteredString(0, "No valid choice");
displayLCDCenteredString(1, "was made!");
break;
//------------- End of Robot Movement Code -----------------------
AutonomousCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
}
}
task usercontrol()
{
// User control code here, inside the loop
while (true)
{
motor[lwMotor] = vexRT[Ch3] / 2;
motor[rwMotor] = vexRT[Ch2] / 2;
if(vexRT[Btn6U] == 1)
{
motor[iMotor] = 127;
}
else if(vexRT[Btn6D] == 1)
{
motor[iMotor] = -127;
}
else
{
motor[iMotor] = 0;
}
if(vexRT[Btn5U] == 1)
{
motor[lfwAMotor] = 0;
motor[rfwAMotor] = 0;
motor[lfwBMotor] = 0;
motor[rfwBMotor] = 0;
}
else if(vexRT[Btn5U] == 1)
{
motor[lfwBMotor] = 0;
motor[rfwBMotor] = 0;
motor[lfwAMotor] = 0;
motor[rfwAMotor] = 0;
}
else
{
motor[lfwAMotor] = 83;
motor[rfwAMotor] = 83;
motor[lfwBMotor] = 83;
motor[rfwBMotor] = 83;
}}
UserControlCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
}