Page 144 ·
Robotics with the Boe-Bot
PAUSE 200
RETURN
Backward:
FOR counter = 1 TO 64
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
You should recognize the pattern of movement your Boe-Bot makes; it is the same one
made by ForwardLeftRightBackward.bs2. Clearly there are many different ways to
structure a program that will result in the same movements. A third approach is given in
the example below.
Example Program – MovementsWithVariablesAndOneSubroutine.bs2
Here’s another example program that causes your Boe-Bot to perform the same
maneuvers, but it only uses one subroutine and some variables to do it.
You have surely noticed that up to this point each Boe-Bot maneuver has been
accomplished with similar code blocks. Compare these two snippets:
' Forward full speed
FOR counter = 1 TO 64
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
' Ramp down from full speed backwards
FOR pulseCount = 100 TO 1
PULSOUT 13, 750 - pulseCount
PULSOUT 12, 750 + pulseCount
PAUSE 20
NEXT
What causes these two code blocks to perform different maneuvers are changes to the
FOR
StartValue
and
EndValue
arguments, and the
PULSOUT
Duration
arguments.
These arguments can be variables, and these variables can be changed repeatedly during
program run time to generate different maneuvers. Instead of using separate subroutines
with specific
PULSOUT
Duration
arguments for each maneuver, the program below uses
the same subroutine over and over. The key to making different maneuvers is to set the
variables to the correct values for the maneuver you want before calling the subroutine.