RobotC program for VEX PIC only running in debug mode

Hello,
I am new to the forum and I have a puzzling problem: The code I include below runs in debug mode but does nothing in normal running mode. If I replace the line:
while(SensorValue(LimitSwitch) == 0)
with:
while(true)
then the program works in normal mode (waits for button presses of TopL or TopR).
Anyone knows what is happening here?
Thanks in advance.

(here is the code)

#pragma config(Sensor, in13, LimitSwitch, sensorTouch)
#pragma config(Sensor, in14, TopL, sensorTouch)
#pragma config(Sensor, in15, TopR, sensorTouch)
#pragma config(Motor, port1, Servo, tmotorServoStandard, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

signed int lidClosed = 0;
signed int lidOpen = 0;
signed int lastPos = 0;

task main()
{
// Set Lid open and close positions by pressing
// Top left and right bumpers, then press
// the Limit sw to continue
while(SensorValue(LimitSwitch) == 0)
{
while(SensorValue(TopR) == 1)
{
lidClosed = lastPos + 1;
if(lidClosed <= 127)
{
motor[Servo] = lidClosed;
++lidClosed;
lastPos = lidClosed;
wait10Msec(1);
}
}
while(SensorValue(TopL) == 1)
{
lidOpen = lastPos - 1;
if(lidOpen >= -127)
{
motor[Servo] = lidOpen;
–lidOpen;
lastPos = lidOpen;
wait10Msec(1);
}
}
}
}

I put your code inside of code blocks.

#pragma config(Sensor, in13, LimitSwitch, sensorTouch)
#pragma config(Sensor, in14, TopL, sensorTouch)
#pragma config(Sensor, in15, TopR, sensorTouch)
#pragma config(Motor, port1, Servo, tmotorServoStandard, openLoop)
//*!!Code automatically generated by ‘ROBOTC’ configuration wizard !!*//

signed int lidClosed = 0;
signed int lidOpen = 0;
signed int lastPos = 0;

task main()
{
   // Set Lid open and close positions by pressing
   // Top left and right bumpers, then press
   // the Limit sw to continue
   while(SensorValue(LimitSwitch) == 0)
   {
      while(SensorValue(TopR) == 1)
      {
         lidClosed = lastPos + 1;
         if (lidClosed <= 127)
        {
           motor[Servo] = lidClosed;
          ++lidClosed;
           lastPos = lidClosed;
           wait10Msec(1);
        } // end if
      } // end while 
   while(SensorValue(TopL) == 1)
   {
      lidOpen = lastPos - 1;
     if (lidOpen >= -127)
     {
         motor[Servo] = lidOpen;
         –lidOpen;
         lastPos = lidOpen;
         wait10Msec(1);
      } // end if
     }  // end while 
   } // end while
}end main

I’m taking your subject at face value that you are using a PIC.

What happens if you replace the line

while(SensorValue(LimitSwitch) == 0)

with

while(SensorValue(LimitSwitch) == 1)
1 Like

Hi,
Yes, it’s a VEX PIC. Changing the test on the LimitSwitch does nothing in normal running mode and - correctly - ends the program without anything happening.