I 'd use what Henrik has posted and maybe with a smaller multiplier, say 3000. Keep your ten average pile. Then Henrik's lines will give you directly the result for your digital pot.
Code:
'Main Program ****************************
'get avg depth
pause 1000
for x = 1 to 10
pulsin gpio.4,1,inputpulse
dist= dist + inputpulse
pause 100
next x
newtapsetting = (dist ** 3060) - 42 'try also a number smaller, 3000
IF newtapsetting > 127 THEN newtapsetting = 127
serout gpio.0,t9600,[12,"avg :", #avgdist,13]
serout gpio.0,t9600,["tap :", #newtapsetting]
pause 500
end
Ioannis
Bookmarks