Download Print this page

Intel Galileo Hardware Manual page 29

Biobots
Hide thumbs Also See for Galileo:

Advertisement

Hardware
Now we need to look at the code.
As with the DC motor activity, we have to start by inserting the servo library. Since that is already on the
Arduino IDE, we don't have to do any other steps but note it at the top of the code, written as:
#include <Servo.h>
Next, we will have to name our servo. The example provided names your servo as 'myservo'. You can
change this if you want or just keep it as is. Finally, we have to define our servo's starting position, the way
that we do that is by setting a variable to 0 degrees (the starting position). We can write this as:
int pos = 0;
Now moving onto the setup, we need to connect or servo via the signal wire (yellow wire on my servo) to
the Galileo. We are going to attach it to pin 9, the way we can write that is:
myservo.attach(9);
We are now able to communicate with our servo motor.
Since we are set up, all we have to do is tell the motor what to do. This is where the code can become very
unique and the programmer has a lot of ability to change the way the servo moves. To start out moving
your servo you need to write a function:
for(pos=0; pos <180; pos +=50)
Lesson 4, Figure 8
Hardware 29

Advertisement

loading