122-27400 Parallax Inc, 122-27400 Datasheet - Page 50

MANUAL FOR SUMOBOT

122-27400

Manufacturer Part Number
122-27400
Description
MANUAL FOR SUMOBOT
Manufacturer
Parallax Inc
Datasheet

Specifications of 122-27400

Accessory Type
Manual
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
SumoBot®
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Page 40 · SumoBot – Mini Sumo Robotics
' -----[ Variables ]-------------------------------------------------------
irBits
irLeft
irRight
' -----[ Program Code ]----------------------------------------------------
Main:
Two bit-sized variables are declared to store the value of each IR detector output. The
command FREQOUT LfIrOut, 1, 38500 sends the [unfiltered] modulation signal
to the left IR LED, causing it to flash on and off rapidly. The harmonic contained in this
signal either bounces off an object, or not. If it bounces off an object and is seen by the
IR detector, the IR detector sends a low signal to I/O pin LfIrIn . Otherwise, the IR
detector sends a high signal to LfIrIn . The bitwise invert operator (~) is used so that a
"hit" (reflection from the opponent) is indicated by "1" and a "miss" is indicated by a "0."
So long as the next command after the FREQOUT command is the one testing the state of
the IR detector’s output, it can be saved as a variable value in RAM. This is possible as
the IR detector output is held active a short time after the signal goes away. The
statement irLeft = ~LfIrIn checks LfIrIn , and saves the value (“1” for hit or “0”
for miss) in the irLeft bit variable. This process is repeated for the other IR pair, and the
IR detector’s output is saved in the irRight variable. The DEBUG statement then displays
the values in the Debug Terminal.
DO
LOOP
END
FREQOUT LfIrOut, 1, 38500
irLeft = ~LfIrIn
FREQOUT RtIrOut, 1, 38500
irRight = ~RtIrIn
DEBUG HOME,
PAUSE 20
"L
"----", CR,
BIN1 irLeft, "
R", CR,
VAR
VAR
VAR
Nib
irBits.BIT1
irBits.BIT0
", BIN1 irRight
' storage for IR target data
' modulate left IR LED
' read input (1 = target)
' modulate right IR LED
' read input (1 = target)

Related parts for 122-27400