LCD Problems

Hello all I am trying to program the LCD module to choose between different autonomous codes in RobotC and I was able to program it with some help from the sample program, but when I go through the LCD Module I only see my first four autonomous codes and I have eight. Is there a way to make the other code selections show on the LCD screen?

Here is the code I made.

void pre_auton()
{
	SetDriveEncoder (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, "RedMiddle1");
			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, "BlueMiddle1");
			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, "RedMiddle2");
			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, "BlueMiddle2");
			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;
		case 4:
			//Display Fifth Choice
			displayLCDCenteredString(0, "RedHang1");
			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;
		case 5:
			//Display Sixth Choice
			displayLCDCenteredString(0, "BlueHang1");
			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;
		case 6:
			//Display Seventh Choice
			displayLCDCenteredString(0, "RedHang2");
			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;
		case 7:
			//Display Eighth Choice
			displayLCDCenteredString(0, "BlueHang2");
			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;
		}
	}
}

Thank you,
Zach

In this section of the code, in case 3 and beyond you have this:

 
else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count = 0;
			}

When you hit that right button on the LCD after the 4th auton program, it’s just going to cycle back to the first one. You want to change that count = 0 to count++ for case 3 to case 6. Don’t change it for case 7 because you want to cycle back to case 0.

Okay I changed my code like you suggested

void pre_auton()
{
	SetDriveEncoder (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, "RedMiddle1");
			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, "BlueMiddle1");
			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, "RedMiddle2");
			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, "BlueMiddle2");
			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 4:
			//Display Fifth Choice
			displayLCDCenteredString(0, "RedHang1");
			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 5:
			//Display Sixth Choice
			displayLCDCenteredString(0, "BlueHang1");
			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 6:
			//Display Seventh Choice
			displayLCDCenteredString(0, "RedHang2");
			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 7:
			//Display Eighth Choice
			displayLCDCenteredString(0, "BlueHang2");
			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;
		}
	}
}

But now I get a bunch of errors one says unmatched left brace at void pre_auton(), an unmatched left brace after the while loop, an unmatched left brace at switch (cont){, and an unmatched left brace after the else if in case three. I have checked all of the curly braces and it looks to me that each of them as a match, am I wrong?

About halfway down, you start using this illegal expression:


 count = ++; 

Here it is fixed:

void pre_auton()
{
	SetDriveEncoder(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, "RedMiddle1");
			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, "BlueMiddle1");
			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, "RedMiddle2");
			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, "BlueMiddle2");
			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 4:
			//Display Fifth Choice
			displayLCDCenteredString(0, "RedHang1");
			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 5:
			//Display Sixth Choice
			displayLCDCenteredString(0, "BlueHang1");
			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 6:
			//Display Seventh Choice
			displayLCDCenteredString(0, "RedHang2");
			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 7:
			//Display Eighth Choice
			displayLCDCenteredString(0, "BlueHang2");
			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;
		}
	}
}

I haven’t installed ROBOTC since I upgraded my computer, so I can’t double check compilation but that was a major issue that screamed error.

Ohh! I can’t believe I didn’t see that. That fixed the errors thank you very much.:slight_smile: