Hardware 25
Hardware
motor.setSpeed(125);
This commands tells the Galileo what speed to run the motor at. The argument can be any number between
0 and 255. This command is just like using analogWrite, it just changes because motors are treated
slightly dierent by the Galileo. This does tell the motor to move.
So, if we want to just go forward our loop function looks like this:
voidloop(){
motor.run(FORWARD);//preparetogoforward
motor.setSpeed(125); //go at around half
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);
The word “RELEASE” 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:
mymotor is the name of the motor. This can be anything, as long as you keep it the same every time you use
it in the program. 1 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 setup, you don’t have to write any-
thing. Doing something in setup may be helpful if you want the motor to do something once, before starting
the loop. But, since we just want to go back and forth, there is no need for setup.
In loop, 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.