How to program a limit switch

I am trying to code a limit switch to stop a motor from running but when the button on the controller has been pressed the motor moves and the switch is bypassed. Also, I am wondering how to make the motor with a single press of a button on the controller and have it run until the limit switch is hit.

We ended up with something like this for our cata. This would need a ratchet to hold the cata in place when it stops. We’re MS so probably not the best way.

ButtonA.pressed runs a shoot void.

LimitSwitch1.pressed runs a catastop void.

Catastop void stops the cata motor if a readytointake valuable is false. Then sets readytointake true.

Shoot void starts the cata motor, sleeps 100ms, then sets readytointake to false. We added the 100ms sleep to keep the limit switch from triggering again before the cata gear slipped. The motor just runs until the limit switch stops it again

can you copy the code and send it in here.