'GP2D02------------------------------------------------------------------------- ' ' This module contains the functions to read the GP2D02 sensor. ' '------------------------------------------------------------------------------- PUBLIC IRDist as BYTE 'PUBLIC LeftIRDist as BYTE DIM DATA1 as BYTE SUB IRDistance() CALL PutPin(GP2D02StartPinNum,0) CALL SLEEP(30) 'wait 70msec 'CALL SLEEP(20) CALL GP2D02read 'read both sensors 'CALL GP2D02read2 'read both sensors 'RightIRDist = DATA2'save right value IRDist = DATA1 'save value CALL PutPin(GP2D02StartPinNum,1) END SUB SUB GP2D02read() dim bit as byte dim z as byte data1 = 0 ' data2 = 0 bit = 128 for z = 1 to 8 call putpin(GP2D02StartPinNum,1) call putpin(GP2D02StartPinNum,0) 'if (getpin(LGP2D02InPinNum) = 1 ) then ' data2 = data2 or bit 'end if if (getpin(GP2D02InPinNum) = 1) then data1 = data1 or bit end if bit = bit \ 2 next END SUB SUB GP2D02read2() data1 = ShiftIn(GP2D02InPinNum,GP2D02StartPinNum,9) END SUB FUNCTION DistanceToInch() AS Single 'LeftToInch = 130.21198 - 3.0642852 * csng(LeftIRDist) + 0.028569488 * pow(csng(LeftIRDist),2.0) - 0.000117672 * pow(csng(LeftIRDist),3.0) + 0.00000017817851 * pow(csng(LeftIRDist),4.0) 'CALL GetEEProm(Table2 + (clng(LeftIRDist) * 4),LeftToInch,4) IF IRDIst > 230 THEN ELSE 'LeftToInch = IRTable(1,cint(LeftIRDist)) END IF END FUNCTION 'FUNCTION RightToInch() AS Single 'RightToInch = 44.274196 - 0.43973765 * csng(RightIRDist) + 0.00091938479 * pow(csng(RightIRDist),2.0) + 0.0000044909932 * pow(csng(RightIRDist),3.0) - 0.000000015149776 * pow(csng(RightIRDist),4.0) 'CALL GetEEProm(Table1 + (clng(RightIRDist) * 4),RightToInch,4) ' IF RightIRDIst > 230 THEN ' ELSE 'RightToInch = IRTable(2,cint(RightIRDist)) ' END IF 'END FUNCTION