|
Page 1 of 1
|
[ 12 posts ] |
|
vex lcd screen auto selector
Author |
Message |
kaiser wolf
Rookie
Joined: Thu May 17, 2012 1:52 am Posts: 4
|
 vex lcd screen auto selector
I'm new to robotc and was wandering if anyone has any code for a autonomous selector using the LCD (like it asks red or blue, left or right side of the field, then you can cycle though numbers for different autonomous runs) also before you start selecting autonomous run it will give you an option for autonomous run or battery powers, and when you finished selecting autonomous run to show the battery power. ps: i am using cortex and i want to check battery levels of main battery, power expander and backup battery if possible. thanks for any help 
|
Thu May 17, 2012 2:02 am |
|
 |
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 409
|
 Re: vex lcd screen auto selector
For an overly thorough example of how to use the buttons on the LCD to select different stuff, go to File > Open Sample Program > Advanced > Cortex View Mode.c
The variable that let you see the values of the battery are "BackupBatteryLevel", "nAvgBatteryLevel", and "nImmediateBatteryLevel".
|
Thu May 17, 2012 1:32 pm |
|
 |
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 409
|
 Re: vex lcd screen auto selector
Here are sample programs that will be included in the next version of ROBOTC:  |  |  |  | Code: #pragma config(UART_Usage, UART2, uartVEXLCD, baudRate19200, IOPins, None, None) #pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed) #pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*----------------------------------------------------------------------------------------------------*\ |* - Code Chooser - *| |* ROBOTC on VEX 2.0 Cortex *| |* *| |* This program uses the Display functions of ROBOTC on the VEX 2.0 Cortex platform. *| |* IIt allows the user to choose from 4 different pieces of code using the left and right buttons *| |* on the VEX LCD. Once the center button is pressed, the code corresponding with the choice is run. *| |* This code can be adapted for competition based settings - just place the code for the first *| |* switch case in the pre_auton function, and the code for the second switch in the autonomous task. *| |* *| |* ROBOT CONFIGURATION *| |* NOTES: *| |* 1) The LCD Screen must be attached to UART Port 2. *| |* *| |* MOTORS & SENSORS: *| |* [I/O Port] [Name] [Type] [Description] *| |* UART Port 2 none VEX LCD VEX LCD Screen *| |* Motor Port 2 rightMotor VEX 3-wire module Right side motor *| |* Motor Port 3 leftMotor VEX 3-wire module Left side motor *| \*----------------------------------------------------------------------------------------------------*/
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() { //Clear LCD clearLCDLine(0); clearLCDLine(1); //Declare count variable to keep track of our choice int count = 0; //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; } } //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[rightMotor] = 127; // Motor on port2 is run at full (127) power forward motor[leftMotor] = 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[rightMotor] = -127; // Motor on port2 is run at full (-127) power reverse motor[leftMotor] = -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 three seconds motor[rightMotor] = -63; // Motor on port2 is run at half power reverse motor[leftMotor] = 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
// Move forward at full power for 3 seconds motor[rightMotor] = 63; // Motor on port2 is run at half power forward motor[leftMotor] = -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; } } |  |  |  |  |
 |  |  |  | Code: #pragma config(UART_Usage, UART2, uartVEXLCD, baudRate19200, IOPins, None, None) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*----------------------------------------------------------------------------------------------------*\ |* - Display Battery Voltage - *| |* ROBOTC on VEX 2.0 Cortex *| |* *| |* This program uses the Display functions of ROBOTC on the VEX 2.0 Cortex platform. *| |* It will display the value of the main battery on line 0 and backup battery on line 1. *| |* *| |* ROBOT CONFIGURATION *| |* NOTES: *| |* 1) The LCD Screen must be attached to UART Port 2. *| |* *| |* MOTORS & SENSORS: *| |* [I/O Port] [Name] [Type] [Description] *| |* UART Port 2 none VEX LCD VEX LCD Screen *| \*----------------------------------------------------------------------------------------------------*/
task main() { bLCDBacklight = true; // Turn on LCD Backlight string mainBattery, backupBattery; while(true) // An infinite loop to keep the program running until you terminate it { clearLCDLine(0); // Clear line 1 (0) of the LCD clearLCDLine(1); // Clear line 2 (1) of the LCD //Display the Primary Robot battery voltage displayLCDString(0, 0, "Primary: "); sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V'); //Build the value to be displayed displayNextLCDString(mainBattery); //Display the Backup battery voltage displayLCDString(1, 0, "Backup: "); sprintf(backupBattery, "%1.2f%c", BackupBatteryLevel/1000.0, 'V'); //Build the value to be displayed displayNextLCDString(backupBattery); //Short delay for the LCD refresh rate wait1Msec(100); } } |  |  |  |  |
|
Thu May 17, 2012 5:29 pm |
|
 |
kaiser wolf
Rookie
Joined: Thu May 17, 2012 1:52 am Posts: 4
|
 Re: vex lcd screen auto selector
thanks will try them out when i get the chance 
|
Fri May 18, 2012 3:21 am |
|
 |
badtkee
Rookie
Joined: Wed Jul 18, 2012 11:21 am Posts: 1
|
 Re: vex lcd screen auto selector
so does this program allow you to make another choice? Once the autonomous route you selected is done, can you select a new route to run?
|
Wed Jul 18, 2012 11:23 am |
|
 |
jokai
Rookie
Joined: Sat Mar 19, 2011 2:32 am Posts: 14
|
 Re: vex lcd screen auto selector
Is there a limit to the number of choices? Thank you.
|
Mon Oct 01, 2012 1:10 am |
|
 |
kaiser wolf
Rookie
Joined: Thu May 17, 2012 1:52 am Posts: 4
|
 Re: vex lcd screen auto selector
by default there is 4 choices there, but to add more you just edit the code a bit so here is the default code and to add another one we just copy the last of the chooser things and edit it, so it would look like  |  |  |  | Code: //Clear LCD clearLCDLine(0); clearLCDLine(1); //Declare count variable to keep track of our choice int count = 0; //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--; // make sure this is --+ so that when the left button is pressed it decreases the count instead of looping back around to the last auto } else if(nLCDButtons == rightButton) { waitForRelease(); count++; //make sure this is ++ so that when the right button is pressed it increases the count instead of looping back around to the first auto } break; default: count = 0; break; case 4: //make sure to change to 1 above the last one //Display fourth choice displayLCDCenteredString(0, "Autonomous 5"); //change to one above last so it displays the right automous number displayLCDCenteredString(1, "< Enter >"); waitForPress(); //Increment or decrement "count" based on button press if(nLCDButtons == leftButton) { waitForRelease(); count--; // make sure this is -- so that it can decrease the count } else if(nLCDButtons == rightButton) { waitForRelease(); count = 0; // make sure this is 0 so that it loops back around to the first automous if the right button is pressed again } break; default: count = 0; break; } } |  |  |  |  |
hope this helped, sorry if i didnt explain to well
|
Mon Oct 01, 2012 4:09 am |
|
 |
kaiser wolf
Rookie
Joined: Thu May 17, 2012 1:52 am Posts: 4
|
 Re: vex lcd screen auto selector
ohh and forgot to add, you have to add another one to the auto its self so that you can controll it if you made a 5th selection  |  |  |  | Code: #pragma config(UART_Usage, UART2, uartVEXLCD, baudRate19200, IOPins, None, None) #pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed) #pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*----------------------------------------------------------------------------------------------------*\ |* - Code Chooser - *| |* ROBOTC on VEX 2.0 Cortex *| |* *| |* This program uses the Display functions of ROBOTC on the VEX 2.0 Cortex platform. *| |* IIt allows the user to choose from 4 different pieces of code using the left and right buttons *| |* on the VEX LCD. Once the center button is pressed, the code corresponding with the choice is run. *| |* This code can be adapted for competition based settings - just place the code for the first *| |* switch case in the pre_auton function, and the code for the second switch in the autonomous task. *| |* *| |* ROBOT CONFIGURATION *| |* NOTES: *| |* 1) The LCD Screen must be attached to UART Port 2. *| |* *| |* MOTORS & SENSORS: *| |* [I/O Port] [Name] [Type] [Description] *| |* UART Port 2 none VEX LCD VEX LCD Screen *| |* Motor Port 2 rightMotor VEX 3-wire module Right side motor *| |* Motor Port 3 leftMotor VEX 3-wire module Left side motor *| \*----------------------------------------------------------------------------------------------------*/
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() { //Clear LCD clearLCDLine(0); clearLCDLine(1); //Declare count variable to keep track of our choice int count = 0; //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; } }
//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[rightMotor] = 127; // Motor on port2 is run at full (127) power forward motor[leftMotor] = 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[rightMotor] = -127; // Motor on port2 is run at full (-127) power reverse motor[leftMotor] = -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 three seconds motor[rightMotor] = -63; // Motor on port2 is run at half power reverse motor[leftMotor] = 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
// Move forward at full power for 3 seconds motor[rightMotor] = 63; // Motor on port2 is run at half power forward motor[leftMotor] = -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; case 4: //change up one from the last one //If count = 3, run the code correspoinding with choice 4 displayLCDCenteredString(0, "Autonomous 5"); //change 1 up from the last one displayLCDCenteredString(1, "is running!"); wait1Msec(2000); // Robot waits for 2000 milliseconds
// Move forward at full power for 3 seconds motor[rightMotor] = 63; // Motor on port2 is run at half power forward motor[leftMotor] = -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; } }
|  |  |  |  |
also what to change for if you want to add more is in comments //
|
Mon Oct 01, 2012 4:13 am |
|
 |
WarpDrive
Rookie
Joined: Fri Jun 21, 2013 10:30 pm Posts: 4
|
 Re: vex lcd screen auto selector
First, thanks to those who posted the code for running the LCD screen. It helps a lot. However, I have a question about the following: What exactly does this little section of code do? I understand that it inserts values into the constants but why is that done?
const short leftButton = 1; const short centerButton = 2; const short rightButton = 4;
Thanks.
|
Wed Jan 01, 2014 2:49 pm |
|
 |
WarpDrive
Rookie
Joined: Fri Jun 21, 2013 10:30 pm Posts: 4
|
 Re: vex lcd screen auto selector
Nevermind. I figured it out. These are values given to the buttons so the LCD can tell which button was pressed or what combination of buttons. For example, the leftButton pressed by itself causes nLCDButtons to == 1. But if you press both leftButton and centerButton at the same time, you get nLCDButtons == 1+2, or in other words nLCDButtons == 3
|
Wed Jan 01, 2014 6:57 pm |
|
 |
VoltRobotics
Rookie
Joined: Fri Dec 12, 2014 8:17 pm Posts: 2
|
 Re: vex lcd screen auto selector
Hello there,
When I add this code into my original code, do I need to delete task autonomous() ??/
|
Sat Dec 20, 2014 6:21 pm |
|
 |
VoltRobotics
Rookie
Joined: Fri Dec 12, 2014 8:17 pm Posts: 2
|
 Re: vex lcd screen auto selector
Will I be able to use this in a real competition game? If not what do I need to change which will allow me to?
|
Sat Dec 20, 2014 7:26 pm |
|
|
|
Page 1 of 1
|
[ 12 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|