3.7 The Motor
1. Attach the Motor module to P4 on the edge of the motherboard. Connect one of your wheels
to the motor axle.
2. Before writing the program below, let’s have a look at the
serout
and
pulsout
commands in
BASIC. The
serout
command allows you to specify such things as the direction and speed of
the motor. The
pulsout
sends a tiny pulse to brake the motor.
They are written in the following general formats:
SEROUT
pin, baudmode, ( output data )
pin
: this is the pin number the motor is connected to.
baudmode
: is a variable or constant that specifies serial timing and configuration – in our
case we use
T2400
as the baud rate.
output data:
is information that effects the direction and speed of our motor – in our case the
data includes direction (i.e. clockwise or anticlockwise) and speed which ranges from 0 to 255.
PULSOUT
pin, time
pin
: this is the pin number the motor is connected to.
time:
the duration of the pulse, measured in milliseconds.
3. Start the
Programming Editor
or
AXEpad
, or start a new program by using the
File/New/Basic Program menu option and then type in the following program:
symbol
P4 = B.4
' Define Output P4
high
P4
' Set the motor line high
pause
50
' Wait for motor module to be ready
do
' Do the following ...
serout
P4, T2400, ("C",150)
' Drive motor clockwise at speed 150
pause
5000
' Continue for 5000ms (5s)
pulsout
P4, 6
' Send a 6ms pulse to brake the motor
serout
P4, T2400, ("A",150)
' Drive motor anti-clockwise at speed 150
pause
5000
' Continue for 5000ms (5s)
pulsout
P4, 6
' Send a 6ms pulse to brake the motor
loop
' Repeat forever
4. Save your program as
Motorprogram.bas
.
5. Press the F5 key to download your program into the PICAXE on your Versabot motherboard.
6. The motor should turn one way, stop briefly, then turn the other way.
7. Turn the motherboard off to stop the motor.
Содержание Versabot
Страница 1: ...The Versabot Manual July 2009...
Страница 23: ...Step 03 Step 04 Step 05...
Страница 24: ...Step 06 Step 07 Step 08...
Страница 25: ...Step 09 Step 10 Step 11...
Страница 26: ...Step 12 Step 13...