LCD Display Coding

So our robot has an LCD display, and there are things I want it to display, but for some reason can’t.

Here’s what I want to do; Have multiple display options which each display different things. I also want the display to be controlled by two buttons on the controller (to change what is being displayed)

Option 1: Display main and backup battery levels

Option 2: Display the value of our arm potentiometer

Option 3: Display our left and right encoder values

Option 4: Display our team number

Post your code

//|---LCD Display Control---|
if (vexRT[Btn7L] == 1)
{
	if (Display > 0)
	{
		Display = Display - 1;
	}
	else
	{
	}
}
else if(vexRT[Btn7R] == 1)
{
	if (Display < 4)
       {
	        Display = Display + 1;
	}
	else
	{
	}
}

//LCD Display - Display Battery Levels


bLCDBacklight = true;							// Turn on LCD Backlight

if (Display == 1)
{
	string mainBattery, backupBattery;
	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);
}

else if (Display == 2)
{
	string Pot;
	clearLCDLine(0);											// Clear line 1 (0) of the LCD
	clearLCDLine(1);											// Clear line 2 (1) of the LCD

	displayLCDCenteredString(0, "Claw Potentiometer:");

	displayLCDCenteredString(1, "");
	sprintf(Pot, "M: %1.2f B: %1.2f", current_Pot_value);
	displayNextLCDString(Pot);
}
else if (Display == 3)
{
	string leftEncoder, rightEncoder;
	clearLCDLine(0);											// Clear line 1 (0) of the LCD
	clearLCDLine(1);											// Clear line 2 (1) of the LCD


	displayLCDString(0, 0, "Left: ");
	sprintf(leftEncoder, "%1.2f%c", nMotorEncoder[backLeft]); //Build the value to be displayed
	displayNextLCDString(leftEncoder);


	displayLCDString(1, 0, "Right: ");
	sprintf(rightEncoder, "%1.2f%c", nMotorEncoder[backRight]);	//Build the value to be displayed
	displayNextLCDString(rightEncoder);
}
else
{
	clearLCDLine(0);			// Clear line 1 (0) of the LCD
	clearLCDLine(1);			// Clear line 2 (1) of the LCD
	displayLCDCenteredString(0, "3116C");
}

I posted my code above. Sorry if you didn’t get a notification

Hey, does anyone know how to code a LCD to be able to switch to three different autonomous?

Casey

Bear with me, this may take awhile :stuck_out_tongue:
First I’ll address the switching part. You can use a switch for this; you’ll start with this:

int LCDinteger = 1;//Create an integer
switch(LCDinteger)
{
case 1:

break;
case 2:

break;
case 3:

break;
etc.
}

This will make it so that whenever the Lcd integer changes to say 3, it will run the third case/break code so with this you can just make little voids/menus that you can switch in between.

To do this with buttons you would need to make something like this:

if (vexRT[btn8R] == 1)
		{                    
			LCDinteger++;
		}

This would make the LCD integer go up(because of the ++) by 1 each time the right 8 button is pressed. You would also need to make a backwards with button 8L or something and lastly you would need to make something like this:


if(LCDinteger > 3)//Or whatever number of functions you end up having//

{
LCDinteger = 1;//Reset it so that it doesn’t keep scrolling through functions that don’t exist//
}


You would also need to make one of these for going backwards.


Now to display battery values, something like this(Just within a function):

string mainBatteryVoltage;//Make an LCD string//
displayLCDString(0,1,“Main:”);//display “Main:” on the lcd screen//
sprintf(mainBatteryVoltage, “%1.2f%c”, nImmediateBatteryLevel/1000.0, ‘V’);//Take the reading in volts//
displayLCDString(0,7,mainBatteryVoltage);//Display it//


This would work for the regular/7.2 volt battery. For the backup/9 volt battery you would just replace the nImmediateBatteryLevel with BackupBatteryLevel divided by 280 instead of 1000(I think).

Now to display the pot value:

displayLCDCenteredString(0, “Pot:”);//Display “Pot:” on line 1//
displayLCDNumber(0, 5, sensorValue[Potentiometer]);//Display the pot value on line 1 but 5 spaces over from the left//


Then you can just replace Potentiometer with whatever your name is for it.

Now for the encoder values it's exactly the same thing as above just with the encoder values. Please note that both of these values require(I think) 5 spaces so don't choose too long of a name :P

Now for the team number. That would be a really simple thing like this:

displayLCDCenteredString(0, “Team number”);//Put in your team number//

Also, you need to put each of those displaying things into a void function(which I assume you know how to do, if not just ask for help :)) and then you’ll be able to post each one into a different case/break statement and cycle through them with the remote buttons.

https://vexforum.com/t/lcd-code-chooser-example/39189/1

This won’t work as intended. The button would be read too quickly and a single press would be interpreted multiple times. You need some sort of “debounce” code.

Easy options are

  1. Detect when the button is pressed not when the button is down
    2.wait until a button is released before moving on

Ok. My bad. I thought you could get by without it but i guess not.
For that you would need to have something to clear the lcd and a while loop like this(their are other ways to do this but this is just how i do it):

if (vexRT[btn8R] == 1)
		{                    
	        LCDinteger++;
                ClearLCD ();
                While(vexRT [btn8U] == 1)
                {
                  Wait10Msec (1);
                }
		} 

There you go. This should work. I use the lcd buttons instead of remote buttons but they are both basically the same so this should be ok :slight_smile:

P.S. I’m surprised that’s the only non-working part of my code you found :stuck_out_tongue:
That made my day :slight_smile: