Datasheet
Chapter 3: EEPROM Tricks and Program Tips ยท Page 81
The IR receivers are active-low, meaning they send a low signal to signify the active
condition (IR signal detected). When your SumoBot is dealing with lots of sensors, the
programming and trouble shooting will all be easier if they are all active-high.
The problem is this:
irLF stores a 0 when an object is detected and a 1 when it is not.
Instead, we want
irLF to store the opposite, a 1 when an object is detected, and a 0 when
it is not. This problem is solved by placing the invert bits operator, a tilde (~), in front of
IrSenseLF in the statement:
irLF = ~IrSenseLF
Now, if IrSenseLF stores a 1, the ~ operator inverts this value to 0 before copying it to
irLF. Likewise, if IrSenseLF stores a 0, the ~ operator inverts it to 1 before storing it in
irLF.
Testing the IR Detectors
The next example program tests the IR object detectors for basic functionality. When the
IR object detectors connected to the X8 and X9 headers are pointed straight ahead, their
detection pattern look roughly like Figure 3-3. While running
TestFrontIrObjectDetectors.bs2, the Debug Terminal should display a 1 when an object is
detected, and a 0 when it's not. In the figure, the SumoBot has detected an opponent with
the right detector, but not with its left. In later activities, you will experiment with
navigation corrections to get the opponent centered and engaged head-on.