Datasheet
Page 94· Applied Robotics with the SumoBot
' -----[ Initialization ]-----------------------------------------------------
DEBUG CLS, "FRONT IR DETECTORS", CR, ' Display heading
"Frequency Left Right", CR,
"--------- ---- -----", CR
' -----[ Main Routine ]-------------------------------------------------------
FOR frequency = 36000 TO 42000 STEP 500
FREQOUT IrLedLF, 1, frequency ' Left IRLED shines IR light
irLF = ~IrSenseLF ' Save IR receiver output
FREQOUT IrLedRF, 1, frequency ' Repeat for right IRLED/receiver
irRF = ~IrSenseRF
DEBUG CR, DEC frequency, CRSRX, 11 ' Display yes/no for detection
IF irLF = 1 THEN DEBUG "yes" ELSE DEBUG "no"
DEBUG CRSRX, 19
IF irRF = 1 THEN DEBUG "yes" ELSE DEBUG "no"
PAUSE 50 ' Delay for slower PCs
NEXT
Your Turn - Frequency Constants
Sometimes it is useful to “comment-out” a line of code in your program by placing an
apostrophe to the left of it, effectively removing it from your executable code without
removing it from your program. It's a good idea to keep some commented-out
IrFreq
constants along with the one you use regularly, as in the example below. That way, you
can comment and uncomment various constants depending on what environment you are
testing in. For example, when prototyping maneuvers, it's better to make your SumoBot
nearsighted so that it only detects an object when you place your hand close to the sensor
you want to detect an object. Medium range might work better for a competition ring in
tight quarters, and maximum range might work better for a competition ring in a spacious
area.
' -----[ Constants ]----------------------------------------------------------
IrFreq CON 39500 ' Maximum range
' IrFreq CON 38500 ' Medium range
' IrFreq CON 41500 ' Close range