Page 220 ·
Robotics with the Boe-Bot
√
Point the light collecting surfaces of your photoresistors upward and outward
shown in Figure 6-12.
Figure 6-12:
Photoresistor Orientation
P15
P14
P13
P12
P11
P10
P9
P8
P7
P5
P2
P1
P0
P6
P4
P3
X2
X3
Vdd
Vss
Vin
+
Programming the Roaming Toward the Light Behavior
The key to roaming toward brighter light sources is going straight ahead when the
differences between the photoresistor measurements are small, and turning toward the
smaller photoresistor measurement when there is a large difference between the two
measurements. In effect, this means the Boe-Bot will turn toward bright light.
Initially this seems like a simple enough programming task;
IF…THEN
reasoning like this
example below should work. The problem is, it doesn’t because the Boe-Bot gets stuck
turning left and then right again because the change in
timeLeft
and
timeRight
is too
large. Each time the Boe-Bot turns a little, the
timeRight
and
timeLeft
variables
change so much that the Boe-Bot tries to correct and turn back. It never manages to get
any forward pulses in.
IF (timeLeft > timeRight) THEN ' Turn right.
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (timeRight > timeLeft) THEN ' Turn left.