Datasheet

Tactile Navigation with Whiskers ยท Page 167
' Robotics with the Boe-Bot - TestWhiskers_UpdateEaOnNewLine.bs2
' Update each whisker state on a new line.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "WHISKER STATES", CR,
"Left Right", CR,
"------ ------"
DO
DEBUG CRSRXY, 0, 3, "P5 = ", BIN1 IN5 ' Print in Column 0,Row 3
DEBUG CRSRXY, 9, 3, "P7 = ", BIN1 IN7 ' Print in Column 9,Row 3
PAUSE 250 ' Change from 50 to 250
LOOP
E2. Subroutine:
Turn_Away:
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
RETURN
To modify the Main Routine, replace the three GOSUB commands under the first
IF condition with this single line:
GOSUB Turn_Away
P1. The key to solving this problem is to write a statement that makes a beep with
the required parameters:
FREQOUT 4, 100, 4000 ' 4kHz beep for 100ms
This statement must be added to the Main Routine in the appropriate places, as
shown below. The rest of the program is unchanged.
' -----[ Main Routine ]----------------------------------------
DO
IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect
FREQOUT 4, 100, 4000 ' 4 kHz beep for 100 ms
FREQOUT 4, 100, 4000 ' Repeat twice
GOSUB Back_Up ' Back up & U-turn
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN ' Left whisker contacts
FREQOUT 4, 100, 4000 ' 4 kHz beep for 100 ms
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right