Chapter 4: Boe-Bot Navigation · Page 143
Example Program – MovementsWithSubroutines.bs2
√ Enter, save, and run MovementsWithSubroutines.bs2. Hint: you can use the Edit
menu in the BASIC Stamp Editor to copy and paste code blocks from one
program to another.
' Robotics with the Boe-Bot - MovementsWithSubroutines.bs2
' Make forward, left, right, and backward movements in reusable subroutines.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Word
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
GOSUB Forward
GOSUB Left
GOSUB Right
GOSUB Backward
END
Forward:
FOR counter = 1 TO 64
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
PAUSE 200
RETURN
Left:
FOR counter = 1 TO 24
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
PAUSE 200
RETURN
Right:
FOR counter = 1 TO 24
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT