FYI - There are a few different threads on the Ping sensor up on the Lynxmotion forums. There is also a top topic(
http://www.lynxmotion.net/viewtopic.php?f=4&t=4714 ) with links to a bunch of different topics talking about code for different sensors or the like.
But here is some code from one of those threads:
Code:
wdist var word
main:
low p4
pulsout p4, 5
input p4
pulsin p4, 0, toolong, 40000, wdist
wdist = wdist / 148 ;convert for inches
serout s_out, i9600, ["Distance: ", sdec wdist, 13, 10] ;display result in terminal
goto main
toolong: ; if the program gets here the sensor is not functioning, or wired wrong
serout s_out, i9600, ["Timeout, sensor is not working", 13]
goto main
The main differences I see is that they added the input P4 line between the pulseout and the pulsein lines. Also they used the long form of the command with a timeout...
Kurt