Datasheet

Chapter 3: EEPROM Tricks and Program Tips · Page 123
Start by opening all of the following programs:
o TestLedSpeaker.bs2
o TestPushButton.bs2
o TestFrontIrObjectDetectors.bs2
o QtiPulseDecayTrick.bs2
o TestSideIrObjectDetectors.bs2
Save QtiPulseDecayTrick.bs2 as TestAllSensors.bs2
Copy and paste the I/O definitions and variables from the other programs into
your new program.
Add one more bit variable that was not found in the other programs, to store the
state of the pushbutton:
pushbutton VAR Bit
Make subroutines for the speaker, IR detectors, and QTI detectors from the
functional portions of their test programs. If the actual work of a sensor is done
in the program's Main Routine, (like IR object detection), paste that part of the
routine into a subroutine. For example, a
Read_Object_Detectors subroutine
could take four lines from the Main Routine of TestFrontIrObjectDetectors.bs2,
and four more from TestSideIrObjectDetectors.bs2.
Read_Object_Detectors:
FREQOUT IrLedRS, 1, IrFreq ' Right side IR LED headlight
irRS = ~IrSenseRS ' Save right side IR receiver
FREQOUT IrLedRF, 1, IrFreq ' Repeat for right-front
irRF = ~IrSenseRF
FREQOUT IrLedLF, 1, IrFreq ' Repeat for left-front
irLF = ~IrSenseLF
FREQOUT IrLedLS, 1, IrFreq ' Repeat for left side
irLS = ~IrSenseLS
RETURN
The subroutine for the pushbutton needs a different approach. Remember that
pbSense
and
DummyPin both reference P6, which is serving two purposes. It's getting used as an
output when
DummyPin sends the PULSOUT command pulses from the
Read_Line_Sensors subroutine. For P6 to next be used to monitor the pushbutton, it