C++ Limit Switch

I’m trying to program a limit switch into C++ for my robots arm so it doesn’t go too high and break the motor or gears. Can anyone help?


i believe but i may be wrong

You need to check if the limit switch is being pressed. If it is, then you should turn off your lift motors so they refuse to continue going up. Here is pseudocode:
if limitSwitch is pressed
lift motors = 0
end if

Here is some example code written for pros. It stopped the my lift from getting torqued by the motors.

if (partner.get_analog(ANALOG_RIGHT_X) > 50 || partner.get_analog(ANALOG_RIGHT_X) < -50) {
if (LLiftI() >= 0 && RLiftI() >= 0) {
        LiftController(partner.get_analog(ANALOG_RIGHT_X) / 1.3);
      else if (partner.get_analog(ANALOG_RIGHT_X) > 10) {
      liftBraked = false;

@DRow the forums is great but it’s rely hard to share code and it be formatted correctly.

@lerker100 just use code tags, I (jpearman) added them for you

Couldn’t you just take a picture of the code and then post that?

Yes, but if someone wants to copy it. It would be helpful to copy and past.

1 Like

20 characters

Wrap your code in triple backtiks (```) or [code] [/code] tags.

std::cout << “Then your code will be nicely formatted!” << std::endl;

Raw source for this post here, if you’re curious.


Thanks, That needs to be added to the hot bar for posts.