One of the most needed functions in driver mode for a Vex IQ or Vex robot is to keep a motor running continuously for a given function. In this example, we provide you with code to do exactly that. In this example we have a motor connected to port 4 of the Vex IQ Robot Brain. We use two variables. The first, allows only one action per button press. The second, stores the state of the function/motor (e.g. running or stopped). Note: The way this is programmed, if the button is held down, no erratic action of the motor will occur, it will move to the correct state and stay there until the button is released and pressed again.
Be sure to watch the YouTube video which shows this in action!
If you are using RobotC, see our post with code on how to do this in RobotC. Coming soon we will be posting more advanced button latches and eventually how to do this in RobotMesh (Python).
Image of brain code to setup variables and loop on start of brain:
No comments:
Post a Comment