Every time I push the limit switch the variable is a different number? Why? It should just add 1 every time? How can I fix this. I the LED is to turn on after 10 hits on the limit switch and the bumper resets the count and turns off the light.
#pragma config(Sensor, dgtl1, limitswitch, sensorTouch)
#pragma config(Sensor, dgtl2, bumper, sensorTouch)
#pragma config(Sensor, dgtl12, led, sensorLEDtoVCC)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
bool buttonPressed=false;
int counter = 0;
while(true){writeDebugStream("int counter is: %d", counter);
if(SensorValue[limitswitch]==1 && buttonPressed==false){
buttonPressed=true;
counter+=1;
while(SensorValue[limitswitch]==1){
}
}
else if(SensorValue[limitswitch]==0 && buttonPressed==true){
buttonPressed=false;
}
if(SensorValue[bumper]==1){
counter=0;
}
if(counter>=10){
SensorValue[led]=true;
}
else{
SensorValue[led]=false;
}
}
}