I’ve been having some odd stuff happening to my Ping sensor lately. My ping started suddenly going to the “toolong” error piece of my code in my rover arm code. So I tested the sensor out to see if it was working properly with this exact code.
distance var word
mm_distance var word
main
low p11
pulsout p11, 5
input p11
pulsin p11, 0, toolong, 40000, distance
distance = distance/148
mm_distance = (distance*254)/10
mm_distance = mm_distance + 38
pause 60
serout s_out, i9600, "Distance: ", sdec mm_distance, 13,10] ;display result in terminal
goto main
toolong: ; if the program gets here the sensor is not functioning, or wired wrong
sound p9,[5000\5000]
serout s_out, i9600, "Timeout, sensor is not working", 13]
goto main
The sensor worked perfectly just as it should have but contiued to go into an endless loop in the toolong section of the code in my rover arm code. After some troubleshooting I eventually put an hservo command (which there is a lot of in my rover arm code)in my sensor testing code like this.
[code]enablehservo
hservo[p12\0\0]
distance var word
mm_distance var word
main
low p11
pulsout p11, 5
input p11
pulsin p11, 0, toolong, 40000, distance
distance = distance/148
mm_distance = (distance*254)/10
mm_distance = mm_distance + 38
pause 60
serout s_out, i9600, "Distance: ", sdec mm_distance, 13,10] ;display result in terminal
goto main
toolong: ; if the program gets here the sensor is not functioning, or wired wrong
sound p9,[5000\5000]
serout s_out, i9600, “Timeout, sensor is not working”, 13]
goto main
[/code]
The same thing happened as it did in my rover arm code and it went into an endless sensor error loop. So I can pretty much conclude that hservo has somehow started effecting my sensor input and I just can’t figure out why.
I’ve tried checking my wire connections and even reinstalling Basic Atom Pro onto my computer but the same issue persists. So I really need a code guru’s help now. Thanks for any help in advance.