Vexcode IQ - Program button to spin motor to specific position

We are trying to build code in the UI, so that pressing/releasing a button will move the motor to a specific position, so that way you can click the button once and release and it moves to a specific position, no need to hold it and guess where to stop. We have an IF condition that if the current position is outside the wanted position, to spin the motor to the correct position and stop. If the current position is accurate, then it does nothing. We have this in a Forever as well, so that we can do this unlimited times. We have tried a few variations of code, but are not having luck with it working properly. Sometimes we get the open to work (moving from 0 to 220), sometimes it doesn’t, the close (from 220 to 0) usually won’t work, sometimes it gets stuck in a loop going halfway and goes a little crazy. So I’m attaching the latest code we are working on and hopefully looking for some pointers on what we are doing wrong. Thanks!

vexcode iq - position

image
Try something like this. The robot will know whether the claw is opened or closed based on a variable. Based on that variable, it will hopefully function as intended. Since it is blocking function, the claw will first open or close before repeating the loop. Hope this helps.

3 Likes

Thanks @74656A , this works!

1 Like