Trying to use a limit switch, but whenever it is closed the program breaks from the main while loop. Just want to set a motor to 0 when the switch is activated.
Just use the smart task function “wait until limit switch”
and easy/usefull perk to easyC, very helpfull for quickly making simple programs.
Sorry, this is in teleoperated.
I don’t use EasyC, but here is a pseudo code version of what you are trying to do…I think.
while (SensorValue[limitswitch] == 0) (not pushed)
{
all your normal code here
}
while (SensorValue[limitswitch] == 1) (pushed)
{
set motors to zero
}
You could also use if, else instead of while I suppose…
I think an if else would be better suited for this purpose, as you only want the code related to the limit switch in that part of the program, and the rest separate.
An example for driver control in pseudo code would be:
while(true)
{
The rest of your driver control here
if(limit switch pressed)
Do what you want when the switch is pressed
else
Do what you want when not pressed
}
Sorry for not posting code, but Kevin that is essentially what we have. The problem is that when the switch is tripped the program breaks from the while loop and ends.
The issue might be that in your switch, when the button is being pressed, the code is being help up and can’t continue to loop. Make sure that there are no waits or loops in the switch that can cause an issue, you want just the command to move the motor(if that is what you want to do).
Is your loop setup to repeat forever? If it is, the only reason it should break is if you have code telling it to break.
Well I can’t reproduce the issue now, everything is working as expected. Thanks for the help all.