Coding Motors
Last updated
Was this helpful?
Last updated
Was this helpful?
In this tutorial, we'll show you how to code additional mechanisms on the robot, like an intake or catapult. Specifically, you'll learn how to spin a motor forwards and backwards at the press of a button.
First, add the motor to the devices list. In this example, our motor is named Motor
Next create a function that spins the motor forwards at full voltage:
Now, let's create another function to spin the motor backwards at full voltage:
Thirdly, we need a function to stop the motor from spinning when the button on the controller is released:
All of this code is great, but none of it will run unless we set up the proper callbacks. We'll use the buttons L1 and L2 in this example, but feel free to change it to any buttons you would like. Put the callback code in the main function, so that the controller buttons activate the functions that spin or stop the motor.
Now, download the code and test to see if it works!