Code:
symbol trig = C.1 ; Define pin for Trigger & Echo (All M2, X2 parts)
symbol range = w1 ; 16 bit word variable for range
main: low b.1
pulsout trig,2 ; produce 20uS trigger pulse (must be minimum of 10uS)
pulsin trig,1,range ; measures the range in 10uS steps
pause 20 ; recharge period after ranging completes
; now convert range to cm (divide by 5.8) or inches (divide by 14.8)
; as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range * 10 / 58 ; multiply by 10 then divide by 58
if range < 5 then gosub hig
goto main ; and around forever
hig:
high b.1
pause 10
return
; Note that X2 parts operate at 8MHz instead of 4MHz and so modify the calculation
; let range = range * 10 / 58 / 2 ; multiply by 10 then divide by 58 then divide by 2
the srf works perfectly but if i take it in my hand..the led just flash every 1 min...
please reply