EasyManua.ls Logo

Parallax Boe-Bot - Page 156

Parallax Boe-Bot
360 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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
DO and
LOOP call each of the subroutines in turn. Try this program and note the effect.
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:

Table of Contents

Other manuals for Parallax Boe-Bot