Page 200 · Robotics with the Boe-Bot
ACTIVITY #2: ROAM AND AVOID SHADOWS LIKE OBJECTS
Since the photoresistor dividers behave similarly to whiskers, it’s worth examining
what’s involved in adapting RoamingWithWhiskers.bs2 so that it functions with the
photoresistor dividers.
Adapting RoamingWithWhiskers.bs2 for the Photoresistor Dividers
All you really have to do is adjust the IF…THEN statements so that they monitor IN6 and
IN3, instead of IN7 and IN5. Figure 6-5 demonstrates how to make these changes.
Figure 6-5: Modify RoamingWithWhiskers.bs2 for Use with Photoresistor Dividers
' From RoamingWithWhiskers.bs2
IF (IN5 = 0) AND (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
' Modified for
' RoamingWithPhotoresistor
' Dividers.bs2
IF (IN6 = 0) AND (IN3 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN6 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN3 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
Example Program – RoamingWithPhotoresistorDividers.bs2
√ Open the program RoamingWithWhiskers.bs2 from page 179, and save it as
RoamingWithPhotoresistorDividers.bs2.
√ Make the modifications shown in Figure 6-5.
√ Reconnect power to your board and servos.
√ Run and test the program.