Part 4: Turning the Left Servo
After all of this building, we finally get to write some code. Before this we need to set up our Arduino code project.
Open the Arduino IDE
Instead of using a built in sample, we are going to create our own. Navigate the menu to create a new file.
- File
- New
Rename the file to something more meaningful than sketch. We suggest using mazerunner.
- File
- Save as
- Change the file name to mazerunner
Setup Output for Debugging: Once you have the blank file, update your IDE to contain the following code.
Create a tab for the chassis
- Press the Sketch Action menu button. This is the down arrow located in the upper right corner of the arduino IDE.
- Select the New Tab option
- At the bottom of the screen, you are being asked for a name for your new tab. Enter chassis and press the OK button.
Drive the left servo
Inside the chassis tab, you should have the following code. We will discuss this code in depth in class. Make sure to pay attention. When it comes to adding the right side servo, you will need to know how to modify it yourself.
Update the mazerunner
Now that the chassis code file is in place, we need to update the mazerunner tab to use it.
- Add a call to chassisSetup in the setup function
- Add a call to driveForward in the loop function
Testing
Compile and upload your current sketch to the Arduino to make sure it is working correctly. You may want to attach one of the servo horns from the small bag that came with your servo so you can see the direction it is spinning better. Remember to turn on your battery pack
- note, you will need to keep the arduino plugged into the computer or get a 9V battery to plug into the arduino when running the robot