Continuous rotation servo v2.0
Copyright © Parallax Inc. Parallax Continuous Rotation Servo (#900-00008) v2.0 7/9/2009 Page 5 of 6
BASIC Stamp
Programming Examples
PBASIC has a PULSOUT command that sets the I/O
Pin
to an output and sends a pulse of the specified
Duration
. Since the servo needs this pulse refreshed every 20 ms for continuous operation, the PULSOUT
command is put in a counted FOR…NEXT loop to sustain continuous operation for the specified number
of cycles.
PULSOUT
Pin
,
Duration
Different BASIC Stamp modules use different units for the PULSOUT command's
Duration
argument.
When adapting BS2 code to another BASIC Stamp model, you may need to make adjustments. The table
below lists the PULSOUT ranges for each BASIC Stamp microcontroller. See the BASIC Stamp Manual or
BASIC Stamp Editor Help for more information.
BASIC Stamp Module 1.3 ms 1.5 ms 1.7 ms
BS1
100 150 200
BS2, BS2e, BS2pe
500 750 1000
BS2sx, BS2px, BS2p24/40
1250 1875 2500
The example shown below for a BASIC Stamp 2 causes a servo connected to BASIC Stamp 1/0 pin 12 to
first rotate full-speed clockwise for about 5 seconds, hold still for about 5 seconds, then rotate
counterclockwise for 5 seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
FOR counter = 1 TO 100 ' Rotate clockwise for ~5 seconds
PULSOUT 12, 850
PAUSE 20
NEXT
FOR counter = 1 TO 100 ' Hold still for ~5 seconds
PULSOUT 12, 750
PAUSE 20
NEXT
FOR counter = 1 TO 100 ' Rotate counterclockwise for ~5 seconds
PULSOUT 12, 650
PAUSE 20
NEXT
For more examples with the BASIC Stamp 2, including 2-wheeled robot maneuvers and ramping, see
"Robotics with the Boe-Bot" Chapter 4, available for free download from the 28132 product page at
www.parallax.com
.