Chapter 4: Boe-Bot Navigation
· Page 149
while a certain condition exists. Our example program will use
DO…LOOP UNTIL
(condition)
. In this case, it causes the
DO…LOOP
to keep repeating until the character
“Q” is read from EEPROM.
A
SELECT
...
CASE
...
ENDSELECT
statement can be used to select a variable and evaluate it
on a case-by-case basis and execute code blocks accordingly. Here is the code block that
will look at each letter value held in the
instruction
variable and then call the
appropriate subroutine for each instance, or case, of a given letter.
SELECT instruction
CASE "F": GOSUB Forward
CASE "B": GOSUB Backward
CASE "R": GOSUB Right_Turn
CASE "L": GOSUB Left_Turn
ENDSELECT
Here are these concepts, all together in a single program.
Example Program: EepromNavigation.bs2
√
Carefully read the code instructions and comments in EepromNavigation.bs2 to
understand what each part of the program does.
√
Enter, save, and run EepromNavigation.bs2.
' Robotics with the Boe-Bot - EepromNavigation.bs2
' Navigate using characters stored in EEPROM.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
' -----[ Variables ]----------------------------------------------------------
pulseCount VAR Word ' Stores number of pulses.
address VAR Byte ' Stores EEPROM address.
instruction VAR Byte ' Stores EEPROM instruction.
' -----[ EEPROM Data ]--------------------------------------------------------
' Address: 0123456789
' These two commented lines show
' ||||||||||
' EEPROM address of each datum.
DATA "FLFFRBLBBQ"
' Navigation instructions.
' -----[ Initialization ]-----------------------------------------------------