I think there are several places up on the forum that show how to convert the IR values into things like cms… Here is some code from one of my Rover programs:
(I am not sure, but this code may have come originally from Xan)
; This table is used to convert Sharp IR readings into CM
IRCMTable bytetable 80,80,80,80,80,80,80,80,80,78, |
76,74,72,70,68,66,64,62,60,59, |
58,57,55,53,52,51,50,49,48,47, |
45,43,42,41,40,39,38,37,35,33, |
32,31,30,30,29,29,28,28,27,27, |
26,26,26,25,25,25,24,24,24,23, |
23,22,22,21,21,20,20,20,19,19, |
18,18,18,17,17,16,16,16,15,15, |
15,14,14,13,13,13,12,12,11,11, |
11,10,10,10,10,10,10,10,10,10
;--------------------------------------------------------------------
;[GetIRSensorInCM]
IRPin var byte
scanrange var word ' A/D result variable
GetIRScanInCM[IRPIN]
; first read in the IRvalue.
adin IRPin,scanrange
; If it is greater than 512 it is out of range we will return 0
IF scanrange > 512 THEN ; outside our table so return 0 to signal too close
return 0
ENDIF
; now convert entry to cm from table. Old program
; divided value by 5.12 using floating point, but could simply multiply by 100 and divide by 512
; in integer math, which should be a lot quicker. 512*100 < 65536 so fits in word...
return IRCMTable((scanrange*100)/512)
Kurt