Chapter 5: Tactile Navigation with Whiskers
· Page 177
Programming the LED Whisker Testing Circuits
√
Reconnect power to your board.
√
Save TestWhiskers.bs2 as TestWhiskersWithLeds.bs2.
√
Insert these two
IF
...
THEN
statements between the
PAUSE
50
and
LOOP
commands.
IF (IN7 = 0) THEN
HIGH 1
ELSE
LOW 1
ENDIF
IF (IN5 = 0) THEN
HIGH 10
ELSE
LOW 10
ENDIF
These are called
IF…THEN
statements, and they will be more fully introduced in the next
activity. These statements are used to make decisions in PBASIC. The first of the two
IF…THEN
statements sets P1 high, which turns the LED on when the whisker connected to
P7 is pressed (
IN7 = 0
). The
ELSE
portion of the statement makes P1 go low, which
turns the LED off when the whisker is not pressed. The second
IF…THEN
statement does
the same thing for the whisker connected to P5 and the LED connected to P10.
√
RunTestWhiskersWithLeds.bs2.
√
Test the program by gently pressing the whiskers. The red LEDs should light up
when each whisker has made contact with its 3-pin header.
ACTIVITY #3: NAVIGATION WITH WHISKERS
In Activity #1, the BASIC Stamp was programmed to detect whether a given whisker
was pressed. In this activity, the BASIC Stamp will be programmed to take advantage of
this information to guide the Boe-Bot. When the Boe-Bot is rolling along and a whisker
is pressed, it means the Boe-Bot bumped into something. A navigation program needs to
take this input, decide what it means, and call a set of maneuvers that will make the Boe-
Bot back up from the obstacle, turn, and go in a different direction.