Parallax Boe-Bot Student Manual page 156

Hide thumbs Also See for Boe-Bot:
Table of Contents

Advertisement

Page 142 · Robotics with the Boe-Bot
DEBUG "Command in subroutine", CR
PAUSE 1000
RETURN
Watch your Debug Terminal, and press the Reset button a few times. You
should get the same set of three messages in the right order each time.
Here's an example program that has two subroutines. One subroutine makes a high
pitched tone while the other makes a low pitched tone. The commands between
call each of the subroutines in turn. Try this program and note the effect.
LOOP
Example Program – TwoSubroutines.bs2
Enter, save, and run TwoSubroutines.bs2
' Robotics with the Boe-Bot - TwoSubroutines.bs2
' This program demonstrates that a subroutine is a reusable block of commands.
' {$STAMP BS2}
' {$PBASIC 2.5}
DO
GOSUB High_Pitch
DEBUG "Back in main", CR
PAUSE 1000
GOSUB Low_Pitch
DEBUG "Back in main again", CR
PAUSE 1000
DEBUG "Repeat...",CR,CR
LOOP
High_Pitch:
DEBUG "High pitch", CR
FREQOUT 4, 2000, 3500
RETURN
Low_Pitch:
DEBUG "Low pitch", CR
FREQOUT 4, 2000, 2000
RETURN
Let's try putting the forward, left, right, and backward navigation routines inside
subroutines. Here's an example:
and
DO

Advertisement

Table of Contents
loading

Table of Contents