Datasheet

Chapter 3: EEPROM Tricks and Program Tips ยท Page 137
DO ' DO...LOOP repeats indefinitely
GOSUB Read_Line_Sensors ' Look for lines
GOSUB Read_Object_Detectors ' Look for objects
GOSUB Read_Pushbutton ' Check pushbutton
DEBUG CRSRXY, 0, 4, BIN8 sensors ' Display Sensors Variable
' Delay for slower PCs
PAUSE 100
LOOP
' -----[ Subroutine - Calibrate_Qtis ]----------------------------------------
Calibrate_Qtis:
HIGH qtiPwrLeft ' Turn left QTI on
HIGH qtiSigLeft ' Discharge capacitor
PAUSE 1
' RCTIME qtiSigLeft, 1, qtiLeft ' Measure charge time
RCTIME qtiSigLeft, 1, temp ' <--- New measure charge time
LOW qtiPwrLeft ' Turn left QTI off
multi = temp ' <--- Add
HIGH qtiPwrRight ' Turn right QTI on
HIGH qtiSigRight ' Discharge capacitor
PAUSE 1
' RCTIME qtiSigRight, 1, qtiRight ' Measure charge time
RCTIME qtiSigRight, 1, temp ' <--- New measure charge time
' qtiThreshold = (qtiLeft + qtiRight) / 2 ' Calculate average
multi = (multi + temp) / 2 ' <--- New calculate average
' qtiThreshold = qtiThreshold / 4 ' Take 1/4 average
multi = multi / 4 ' <--- New take 1/4 average
' IF threshold > 220 THEN ' Account for code overhead
' threshold = threshold - 220
' ELSE
' threshold = 0
' ENDIF
IF multi > 220 THEN ' <--- New
multi = multi - 220 ' <--- New
ELSE ' <--- New
multi = 0 ' <--- New
ENDIF ' <--- New