Parallax Boe-Bot Student Manual page 155

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

Advertisement

Figure 4-5 shows part of a PBASIC program that contains a subroutine call and a
subroutine. The subroutine call is the
subroutine is everything from the
Here's how it works. When the program gets to the
it looks for the
My_Subroutine:
the
label and starts executing commands. The program keeps going
My_Subroutine:
down line by line from the label, so you'll see the message "Command in subroutine" in
your Debug Terminal.
program gets to the
RETURN
command immediately after the
that displays the message "After subroutine".
DO
DEBUG "Before subroutine",CR
PAUSE 1000
GOSUB My_Subroutine
DEBUG "After subroutine", CR
PAUSE 1000
LOOP
My_Subroutine:
DEBUG "Command in subroutine", CR
2
PAUSE 1000
RETURN
Example Program – OneSubroutine.bs2
Enter, save, and run OneSubroutine.bs2
' Robotics with the Boe-Bot - OneSubroutine.bs2
' This program demonstrates a simple subroutine call.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Before subroutine",CR
PAUSE 1000
GOSUB My_Subroutine
DEBUG "After subroutine", CR
END
My_Subroutine:
GOSUB My_Subroutine
My_Subroutine:
label. As shown by arrow (1), the program jumps to
causes a one second pause. Then, when the
PAUSE 1000
command, arrow (2) shows how it jumps back to the
command. In this case, it's a
GOSUB
Chapter 4: Boe-Bot Navigation · Page 141
command. The actual
label through the
RETURN
GOSUB My_Subroutine
DEBUG
1
Figure 4-5
Subroutine
Basics
command.
command,
command

Advertisement

Table of Contents
loading

Table of Contents