Chapter 4: Boe-Bot Navigation
· Page 125
the same amount of time, the
EndValue
argument also controls the time the servo runs.
Here’s an example program that will make the Boe-Bot roll forward for about three
seconds.
Example Program: BoeBotForwardThreeSeconds.bs2
√
Make sure power is connected to the BASIC Stamp and servos.
√
Enter, save, and run BoeBotForwardThreeSeconds.bs2.
' Robotics with the Boe-Bot - BoeBotForwardThreeSeconds.bs2
' Make the Boe-Bot roll forward for three seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Word
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
FOR counter = 1 TO 122 ' Run servos for 3 seconds.
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
END
How BoeBotForwardThreeSeconds.bs2 Works
From chapter 2, you already have lots of experience with the elements of this program: a
variable declaration, a
FOR…NEXT
loop,
PULSOUT
commands with
Pin
and
Duration
arguments, and
PAUSE
commands. Here’s a review of what each does and how it relates
to the servos’ motions.
First a variable is declared that will be used in the
FOR
...
NEXT
loop.
counter VAR Word
You should recognize this command; it generates a tone to signal the start of the program.
It will be used in all programs that run the servos.
FREQOUT 4, 2000, 3000 ' Signal program start/reset.