while my team’s robot is still being built I decided to make some code that prints the values of the Joystick sensors to the ROBOTC debug stream (since there is no other way to see them while running the code). for the most part it works. However, I decided to have the accelerometers displayed separately since they are rarely used. So the button you press to show the values of the first joystick (the left LCD button) you can press again to show the accelerometers. That’s where the issue is. press the button once and it works fine, press it a second time and instead of only showing the accelerometers, it tries to show both the values of joystick 1 and the accelerometers at the same time.
also, this isn’t all my code, just the part that isn’t working.
while(true)
{
int LCDMode = 4;
bool LCDLeft = false;
bool LCDCenter = false;
bool LCDRight = false;
if (nLCDButtons == 1 && !LCDLeft && LCDMode != 1 && LCDMode != 2)
{
LCDMode = 1;
LCDLeft = true;
wait1Msec(500);
}
else if (!nLCDButtons == 1 || LCDMode == 1)
LCDLeft = false;
if (nLCDButtons == 1 && !LCDLeft && LCDMode == 1 || LCDMode == 2)
{
LCDMode = 2;
LCDLeft = true;
wait1Msec(500);
}
else if (!nLCDButtons == 1 || LCDMode != 1)
LCDLeft = false;
switch(LCDMode)
{
case 1:// controller 1
displayLCDString(0,0,"Joystick One ");
writeDebugStreamLine("| Analog | Buttons 5 & 6 | Buttons 7 | Buttons 8 |"); //DebugStream Line 1
writeDebugStream(" channel 1: %d", vexRT[Ch1]); //Start of DebugStream Line 2
if(vexRT[Ch1] > 9 && vexRT[Ch1] < 100) // If statements are to keep everything aligned correctly
{
writeDebugStream(" Button 5U: %d", vexRT[Btn5U]);
}
else if(vexRT[Ch1] > 99)
{
writeDebugStream(" Button 5U: %d", vexRT[Btn5U]);
}
else if(vexRT[Ch1] < 0 && vexRT[Ch1] > -10)
{
writeDebugStream(" Button 5U: %d", vexRT[Btn5U]);
}
else if(vexRT[Ch1] < -9 && vexRT[Ch1] > -100)
{
writeDebugStream(" Button 5U: %d", vexRT[Btn5U]);
}
else if(vexRT[Ch1] < -99)
{
writeDebugStream(" Button 5U: %d", vexRT[Btn5U]);
}
else
{
writeDebugStream(" Button 5U: %d", vexRT[Btn5U]);
}
writeDebugStream(" Button 7U: %d", vexRT[Btn7U]);
writeDebugStreamLine(" Button 8U: %d", vexRT[Btn8U]); //End of DebugStream Line 2
writeDebugStream(" channel 2: %d", vexRT[Ch2]); //Start of DebugStream Line 3
if(vexRT[Ch2] > 9 && vexRT[Ch2] < 100)
{
writeDebugStream(" Button 5D: %d", vexRT[Btn5D]);
}
else if(vexRT[Ch2] > 99)
{
writeDebugStream(" Button 5D: %d", vexRT[Btn5D]);
}
else if(vexRT[Ch2] < 0 && vexRT[Ch2] > -10)
{
writeDebugStream(" Button 5D: %d", vexRT[Btn5D]);
}
else if(vexRT[Ch2] < -9 && vexRT[Ch2] > -100)
{
writeDebugStream(" Button 5D: %d", vexRT[Btn5D]);
}
else if(vexRT[Ch2] < -99)
{
writeDebugStream(" Button 5D: %d", vexRT[Btn5D]);
}
else
{
writeDebugStream(" Button 5D: %d", vexRT[Btn5D]);
}
writeDebugStream(" Button 7D: %d", vexRT[Btn7D]);
writeDebugStreamLine(" Button 8D: %d", vexRT[Btn8D]); //End of DebugStream Line 3
writeDebugStream(" channel 3: %d", vexRT[Ch3]); //Start of DebugStream Line 4
if(vexRT[Ch3] > 9 && vexRT[Ch3] < 100)
{
writeDebugStream(" Button 6U: %d", vexRT[Btn6U]);
}
else if(vexRT[Ch3] > 99)
{
writeDebugStream(" Button 6U: %d", vexRT[Btn6U]);
}
else if(vexRT[Ch3] < 0 && vexRT[Ch3] > -10)
{
writeDebugStream(" Button 6U: %d", vexRT[Btn6U]);
}
else if(vexRT[Ch3] < -9 && vexRT[Ch3] > -100)
{
writeDebugStream(" Button 6U: %d", vexRT[Btn6U]);
}
else if(vexRT[Ch3] < -99)
{
writeDebugStream(" Button 6U: %d", vexRT[Btn6U]);
}
else
{
writeDebugStream(" Button 6U: %d", vexRT[Btn6U]);
}
writeDebugStream(" Button 7L: %d", vexRT[Btn7L]);
writeDebugStreamLine(" Button 8L: %d", vexRT[Btn8L]); //End of DebugStream Line 4
writeDebugStream(" channel 4: %d", vexRT[Ch4]); //Start of DebugStream Line 5
if(vexRT[Ch4] > 9 && vexRT[Ch4] < 100)
{
writeDebugStream(" Button 6D: %d", vexRT[Btn6D]);
}
else if(vexRT[Ch4] > 99)
{
writeDebugStream(" Button 6D: %d", vexRT[Btn6D]);
}
else if(vexRT[Ch4] < 0 && vexRT[Ch4] > -10)
{
writeDebugStream(" Button 6D: %d", vexRT[Btn6D]);
}
else if(vexRT[Ch4] < -9 && vexRT[Ch4] > -100)
{
writeDebugStream(" Button 6D: %d", vexRT[Btn6D]);
}
else if(vexRT[Ch4] < -99)
{
writeDebugStream(" Button 6D: %d", vexRT[Btn6D]);
}
else
{
writeDebugStream(" Button 6D: %d", vexRT[Btn6D]);
}
writeDebugStream(" Button 7R: %d", vexRT[Btn7R]);
writeDebugStreamLine(" Button 8R: %d", vexRT[Btn8R]); //End of DebugStream Line 5
wait1Msec(350);
break;
case 2: //Accelerometers
writeDebugStreamLine("| Accelerometers |");
writeDebugStreamLine(" AccelY: %d", vexRT[AccelY]);
writeDebugStreamLine(" AccelX: %d", vexRT[AccelX]);
wait1Msec(350);