LCD Display and Autonomous Struggle

I have begun learning how to display sensor Values on the LCD display and have struggle to make it work.
I have a simple code to drive forward then turn and want to display motor encoder values and gyro values. But when i go to download the code the autonomous function will not run
below is the code that works

void pre_auton()
{
	SensorValue[gyro] = 0;
	wait1Msec(2000);

	bStopTasksBetweenModes = true;

}

task autonomous()
{
	resetMotorEncoder(leftMotor);
	resetMotorEncoder(rightMotor);
	SensorValue[gyro] = 0;
	wait1Msec(2000);

	while(getMotorEncoder(rightMotor) < 1800)
	{
		motor[rightMotor] = 100;
		motor[leftMotor] = 100;
	}

	motor[rightMotor] = 0;
	motor[leftMotor] = 0;
	SensorValue[gyro] = 0;
	wait1Msec(2000);
	while(SensorValue[gyro]>-870)
	{
		motor[rightMotor] = -35;
		motor[leftMotor] = 35;
	}
	motor[rightMotor] = 0;
	motor[leftMotor] = 0;
	AutonomousCodePlaceholderForTesting();  

task usercontrol()
{
	while (true)
	{
		if (vexRT[Btn8U] == true)
		{
			startTask (autonomous);
		}

then when I add this code the autonomous will not run and the screen goes blank(note that leftMotor and rightMotor are calling IME values)

void pre_auton()
{
	SensorValue[gyro] = 0;
	wait1Msec(2000);

	bStopTasksBetweenModes = true;

}

task autonomous()
{
	while(1==1)
	{
		clearLCDLine(0);
		clearLCDLine(1);
		displayLCDCenteredString(0, "Left Gyro Rght");
		displayLCDNumber(1, 0, SensorValue[leftMotor]);
		displayLCDNumber(1, 5, SensorValue[gyro] );
		displayLCDNumber(1, 10,SensorValue[rightMotor] );
		wait1Msec(10);
	}

	resetMotorEncoder(leftMotor);
	resetMotorEncoder(rightMotor);
	SensorValue[gyro] = 0;
	wait1Msec(2000);

	while(getMotorEncoder(rightMotor) < 1800)
	{
		motor[rightMotor] = 100;
		motor[leftMotor] = 100;
	}

	motor[rightMotor] = 0;
	motor[leftMotor] = 0;
	SensorValue[gyro] = 0;
	wait1Msec(2000);
	while(SensorValue[gyro]>-870)
	{
		motor[rightMotor] = -35;
		motor[leftMotor] = 35;
	}
	motor[rightMotor] = 0;
	motor[leftMotor] = 0;
	AutonomousCodePlaceholderForTesting();  
}

task usercontrol()
{
	while (true)
	{
		if (vexRT[Btn8U] == true)
		{
			startTask (autonomous);
		}

With this code i can see this and autonomus will not run

Thank you for the help
Zach
IMG_4068.JPG

Hi Zach

The reason your code does not work as intended is because you have the lcd display in an infinite loop, that is, you have it inside a while(1) loop. This means that you never reach and are able to execute the rest of your autonomous code. The best way to solve this is to place the lcd display code inside a separate task and start that at the beginning of autonomous, something like this.

void pre_auton()
{
  SensorValue[gyro] = 0;
  wait1Msec(2000);

  bStopTasksBetweenModes = true;
}

task lcd()
{
  clearLCDLine(0);
  displayLCDCenteredString(0, "Left Gyro Rght");
  while(1)
    {
    clearLCDLine(1);
    displayLCDNumber(1, 0, SensorValue[leftMotor]);
    displayLCDNumber(1, 5, SensorValue[gyro] );
    displayLCDNumber(1, 10,SensorValue[rightMotor] );
    
    wait1Msec(50);
    }
}

task autonomous()
{
  startTask( lcd );
  
  resetMotorEncoder(leftMotor);
  resetMotorEncoder(rightMotor);
  SensorValue[gyro] = 0;
  wait1Msec(2000);

  while(getMotorEncoder(rightMotor) < 1800)
  {
    motor[rightMotor] = 100;
    motor[leftMotor] = 100;
  }

  motor[rightMotor] = 0;
  motor[leftMotor] = 0;
  SensorValue[gyro] = 0;
  wait1Msec(2000);
  while(SensorValue[gyro]>-870)
  {
    motor[rightMotor] = -35;
    motor[leftMotor] = 35;
  }
  motor[rightMotor] = 0;
  motor[leftMotor] = 0;
  
  AutonomousCodePlaceholderForTesting();  
}