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);
}
}
}
}