stop loop with encoder

Our team is trying to control our arm with an encoder to make the motor start when we push a button and stop when the encoder reads a certain voltage. We are able to make the motor run, however we are unable to stop the motor when the encoder reads that voltage.

We set the loop condition to stop when true (when the voltage is greater than 3) through an accelerometer vi since we are reading voltage. We have tested the encoder with the Accelerometer Angle example, so I’m pretty sure that it is running correctly. I’ve attached our code below and we are stumped as to why it is not working. Also, we noticed that on the driver station the Analog Input gives different values than we expect. Could anyone tell us whether to base our numbers off the readings on the dashboard or the Accelerometer Angle example? Thank you! :slight_smile:





Even if your loop exits, there is nothing to set the motor speed back to 0. You need a motor set output outside the loop to stop the motor. Make sure you wire through the reference from the inside of the loop so the “set to 0” part doesn’t run until the loop is complete.

this seems to have fixed our problem! thank you