Page 272 ·
Robotics with the Boe-Bot
FREQOUT 8,1, irFrequency
irDetect = IN9
' Commands not shown...
NEXT
The first time through the
FOR
…
NEXT
loop,
freqSelect
is 0, so the
LOOKUP
command
places the value 37500 in the
irFrequency
variable. Since
irFrequency
contains
37500 after the
LOOKUP
command, the
FREQOUT
command sends that frequency to the IR
LED connected to P8. As in the previous chapter, the value of
IN9
is then saved in the
irDetect
variable. The second time through the
FOR
…
NEXT
loop, the value of
freqSelect
is now 1, which means the
LOOKUP
command places 38250 into the
irFrequency
variable, and the process is repeated for this higher frequency. The third
time through, it’s repeated again with 39500, and so on. The result is remarkable,
especially considering you are using parts that were designed for a completely different
purpose, to make IR communication between a handheld remote and a television
possible.
Example Program – TestLeftFrequencySweep.bs2
TestLeftFrequencySweep.bs2 does two things. First, it tests the left IR LED/detector pair
(connected to P8 and P9) to make sure they are functioning properly for distance
detection. However, it also demonstrates how the frequency sweep illustrated in Figure
8-2 is accomplished.
When you run the program, the Debug Terminal will display your zone measurement.
There are many possible yes-no patterns that can be generated; two are shown in Figure
8-3. The test patterns will vary depending on the characteristics of the filter inside the IR
detector.
The program determines which zone the detected object is in by counting the number of
“No” occurrences. Notice that even though the two Debug Terminal test patterns in
Figure 8-3 are different, they both have three “Yes” and two “No” occurrences.
Therefore, “Zone 2” is the location of the object detected in both examples.