- toujours encore des problèmes dans les distances >1.2m :-(
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
-- Mesure la distance avec le module ultra-son
|
||||
print("\n ultra_son.lua zf180826.1837 \n")
|
||||
|
||||
print("\n ultra_son.lua zf180826.2253 \n")
|
||||
|
||||
--Parametres pour le module ultra son
|
||||
ztrig=5
|
||||
zecho=6
|
||||
zlength=0
|
||||
gpio.mode(ztrig, gpio.OUTPUT)
|
||||
gpio.write(ztrig, gpio.LOW)
|
||||
gpio.mode(zecho, gpio.INT, gpio.PULLUP)
|
||||
@@ -14,6 +12,9 @@ detectortimer2=tmr.create()
|
||||
|
||||
--Function pour faire envoyer la pulse
|
||||
function zmesure_pulse()
|
||||
|
||||
--gpio.trig(zecho,"up",zup)
|
||||
|
||||
gpio.write(ztrig, gpio.HIGH)
|
||||
tmr.delay(10)
|
||||
gpio.write(ztrig, gpio.LOW)
|
||||
@@ -28,11 +29,31 @@ function zmesure()
|
||||
zlength=math.floor(360*(ultra_son_stop-ultra_son_start)/2/10000)/100
|
||||
if zlength>6 then zlength=0 end
|
||||
disp_mesure()
|
||||
-- print(zlength)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
function zup()
|
||||
--print("up")
|
||||
ultra_son_start=tmr.now()
|
||||
gpio.trig(zecho,"down",zdown)
|
||||
end
|
||||
|
||||
function zdown()
|
||||
ultra_son_stop=tmr.now()
|
||||
zlength=math.floor(360*(ultra_son_stop-ultra_son_start)/2/10000)/100
|
||||
if zlength>6 then zlength=0 end
|
||||
disp_mesure()
|
||||
gpio.trig(zecho,"none")
|
||||
--print("down")
|
||||
end
|
||||
|
||||
|
||||
gpio.trig(zecho,"both",zmesure)
|
||||
--gpio.trig(zecho,"up",zup)
|
||||
|
||||
|
||||
--function disp_mesure() print(zlength) end
|
||||
--tmr.alarm(detectortimer1, 1000, tmr.ALARM_AUTO, zmesure_pulse)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user