Unofficial: Limit Switch Code

Welcome to the forum, Alpha Dream. A few of the boards on here (like RobotC Tech Support) can only be replied to by the web admins. You will get much more help on these open boards. So I am posting your question here. The first thing anyone is going to ask is if you have written any code for this yet. If do, post it here and you will get lots of help.

Help! I have been looking up how to code a limit switch but i never get it right! I am using RobotC. My team and i are trying two different robots at the same time to see which is more efficient. So we need to code a limit switch for an elevator lift and one for a two bar lift.

As a general answer, you use


with the name/port of your limit switch (according to your


statements) in the brackets. It will return 1 when pressed or 0 otherwise.

Just to elaborate on what @Barin said and put it into some real code:

void raiseArm() {
     while(SensorValue[topBumper] == 0) {
          motor[motor1] = motor[motor2] = 100;
     motor[motor1] = motor[motor2] = 0;

This is basically going to raise the arm at motor power 100 as long as the bump switch at the top is not pressed. When it exits the while loop, it will set the motors to 0.

Thank you I will try that