LCD Screen Autonomous Code Programming

Hey guys. My team and I just finished our first competition and we had many things to change. One of the relevations that we had was trying to use an LCD screen to our advantage so we could run multiple autonomous codes, so I was wondering if anyone could help me out in the programming aspect of it.

v5 or v4 and what are you using to program it with.

I am using v4 motors and using RobotC.

Hi avl,
Our team utilizes a switch statement to choose between different autonomouses. We use the right and left buttons to select an autonomous and the center button to select. Is this what you are looking for?

Kind of. One of the other teams at our school recommended the idea to us. They had said based on the circumstances of where you started your match on the field and the contrast between the other team and us you could change which autonomous you wanted through the LCD screen.

search the forum, there are literally dozens of threads showing how to do this. Here is one, not the most simple, there are many others.

Our girls used the one from Renegade Robotics.
https://renegaderobotics.org/our-favorite-lcd-menu-code/

It works well and they have adapted it for use in the actual code so they have pages of information - battery voltages, encoder positions, etc so there is feedback when driving and such.

Thanks so much guys!

Update: Our autonomous code selector works wonderfully.

1 Like

Good to hear!

As I mentioned, our girls adapted this to create a driver control screen that shows many items like encoder positions, ultrasonic sensor readings, battery voltage. One of the screens shows the encoder position on one line and the second has a conversion from encoder pulses to inches, with a button to reset the measurement. This allows them to reset the measurement, drive a distance in driver control, then take the actual measurement and place it in their autonomous code so programming is quicker.

Its a separate task that runs during driver. If I can find a copy, I’ll attach it. It could come in handy.

Here is the driver menu the girls used. This is the first year we really got serious about programming and doing software better. As it stands now, our driver control uses the multitasking features of the cortex and it has lent itself to a much cleaner, easier to understand code. This is a separate task that runs the screen when the robot is in driver control to show multiple pieces of info the girls can use to make things quicker.

// start drivermenu example

task driverscreen()//  display items on the screen to allow for diagnosis
{
	// Leave this value alone; counting starts at 1
	int driverScreenMin = 1;

	//  IMPORTANT!!!
	// Total # menu items ***** Note Adjust this to match your number of screens!!!
	int driverScreenMax = 6;

	// Counter for what to display on the screen
	int driverScreen = 1;

	//Turns on the Backlight
	bLCDBacklight = true;

	// Leave these values alone
	// In RobotC:
	// when the left button is pressed, nLCDButtons = 1
	// when middle button is pressed, nLCDButtons = 2
	// when right button is pressed, nLCDButtons = 4
	const short leftButton = 1;
	const short centerButton = 2;
	const short rightButton = 4;

	string mainBattery, expBattery, lencdist, fusonic, rusonic, lusonic;


	// This section checks whether left & right buttons are
	// pressed, and either increments or decrements the
	// lcdScreen counter; if the counter is at the max or min
	// it will loop around to the other end
	while(1==1)
	{
		// left button
		if (nLCDButtons == leftButton) {
			if (driverScreenMin == driverScreen) {
				driverScreen = driverScreenMax;
				wait1Msec(250);
			}
			else {
				driverScreen= driverScreen-1;
				wait1Msec(250);
			}
		}

		// right button
		if (nLCDButtons == rightButton) {
			if (driverScreenMax == driverScreen) {
				driverScreen = driverScreenMin;
				wait1Msec(250);
			}
			else {
				driverScreen=driverScreen+1;
				wait1Msec(250);
			}
		}

		//------------------------------------------------------------
		if (driverScreen == 1) {
			clearLCDLine(0);
			clearLCDLine(1);
			displayLCDString (0, 0, "LEnc: ");
			displayNextLCDNumber(SensorValue(encoderL));
			displayLCDString (1, 0, "REnc: ");
			displayNextLCDNumber(SensorValue(encoderR));
		}
		//------------------------------------------------------------
		else if (driverScreen == 2 ) {
			clearLCDLine(0);
			clearLCDLine(1);

			//Display the Primary Robot battery voltage
			displayLCDString(0, 0, "MBat: ");
			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, "EBat: ");
			sprintf(expBattery, "%1.2f%c", SensorValue(expBatt)/280.0, 'V');	//Build the value to be displayed
			displayNextLCDString(expBattery);

			//Short delay for the LCD refresh rate
			wait1Msec(100);
		}
		//------------------------------------------------------------
		else if (driverScreen == 3) {
			clearLCDLine(0);
			clearLCDLine(1);
			displayLCDString (0, 0, "LEnc: ");
			displayNextLCDNumber(SensorValue(encoderL));
			displayLCDString (1, 0, "Dist: ");
			sprintf(lencdist, "%3.2f", SensorValue(encoderL)*cir/360);
			displayNextLCDString(lencdist);

			if (nLCDButtons == centerButton) {
				SensorValue(encoderL) = 0;
				SensorValue(encoderR) = 0;
			}
			//------------------------------------------------------------
			else if (driverScreen == 4) {
				clearLCDLine(0);
				clearLCDLine(1);
				displayLCDCenteredString (0, "Front Ultrasonic");
				sprintf(fusonic, "3.2f", SensorValue(front));
				displayLCDCenteredString (1, fusonic);
			}
			//------------------------------------------------------------
			else if (driverScreen == 5) {
				clearLCDLine(0);
				clearLCDLine(1);
				displayLCDCenteredString (0, "Left Ultrasonic");
				sprintf(lusonic, "3.2f", SensorValue(left));
				displayLCDCenteredString (1, lusonic);
			}

			//------------------------------------------------------------
			else if (driverScreen == 6) {
				clearLCDLine(0);
				clearLCDLine(1);
				displayLCDCenteredString (0, "Right Ultrasonic");
				sprintf(rusonic, "3.2f", SensorValue(right));
				displayLCDCenteredString (1, rusonic);
			}



		}

		//------------------------------------------------------------

	}// end while loop for screen

} // end driver screen
// end driver menu example