Download Print this page

Intel Galileo Hardware Manual page 25

Biobots
Hide thumbs Also See for Galileo:

Advertisement

Hardware
mymotor
is the name of the motor. This can be anything, as long as you keep it the same every time you use
1
it in the program.
is the motor number, there should be labels M1, M2, M3, and M4 on the chip. If not, OUT1
and OUT2 should correspond to motor 1. (OUT3 and OUT4 are for motor 2).
First let's write a basic program that moves the motor back and forth. In
thing. Doing something in
loop
the
. But, since we just want to go back and forth, there is no need for
loop
In
, we want to do two things: make the motor go forward, then make the motor go backwards. In or-
der to not break the motor, we should probably tell it to: go forward, stop, go backwards, stop. Motors don't
always like to change direction without stopping in between.
To go forward, we have to use two commands:
motor.run(FORWARD);
This command tells the Galileo that we are going to go forwards with the motor. It does not tell the motor to
move, though.
motor.setSpeed(125);
This commands tells the Galileo what speed to run the motor at. The argument can be any number between
0
255
and
. This command is just like using
slightly different by the Galileo. This does tell the motor to move.
So, if we want to just go forward our
void loop(){
speed
Test this program, to make sure your motor goes forward correctly. To make the motor stop we can tell the
Galileo this:
motor.run(RELEASE);
RELEASE
The word "
" just means to stop the motor, to release it. Note that there is no need to set the speed,
it's stopped. We can now make the motor go forward for one second, stop for one second, and repeat:
setup
may be helpful if you want the motor to do something once, before starting
analogWrite
loop
function looks like this:
motor.run(FORWARD); //prepare to go forward
motor.setSpeed(125); //go at around half
}
setup
, you don't have to write any-
setup
, it just changes because motors are treated
.
Hardware 25

Advertisement

loading