Just wondering if anyone here can help me with the code?
I couldn’t get it work.
Have been trying all day long, but no luck
I couldn’t figure out the right number for Trigger and Scale
Here is my code: (Code are based on example given by parallax)
’ ----- I/O Definitions ]-------------------------------------------------
Ping CON P15
’ ----- Constants ]-------------------------------------------------------
Trigger CON 10
Scale CON $A00
RawToIn CON 889 ’ 1 / 73.746 (with **)
RawToCm CON 2257 ’ 1 / 29.034 (with **)
’ ----- Variables ]-------------------------------------------------------
rawDist VAR Word ’ raw measurement
inches VAR Word
cm VAR Word
’ ----- Initialization ]--------------------------------------------------
’ ----- Program Code ]----------------------------------------------------
Main:
GOSUB Get_Sonar ’ get sensor value
inches = rawDist ** RawToIn ’ convert to inches
cm = rawDist ** RawToCm ’ convert to centimeters’’
gosub Distance
PAUSE 100
goto Main
’ ----- Subroutines ]-----------------------------------------------------
’ This subroutine triggers the Ping sonar sensor and measures
’ the echo pulse. The raw value from the sensor is converted to
’ microseconds based on the Stamp module in use. This value is
’ divided by two to remove the return trip – the result value is
’ the distance from the sensor to the target in microseconds.
Distance:
DEBUG [0, "Parallax Ping Sonar "]
DEBUG [13, “=====================”]
DEBUG [13, "Time (uS)… ", dec rawDist]
DEBUG [13, "Inches… ", dec inches]
DEBUG [13, "Centimeters… ", dec cm]
RETURN
Get_Sonar:
LOW Ping ’ make trigger 0-1-0
PULSOUT Ping, Trigger ’ activate sensor
PULSIN Ping, 1, rawDist ’ measure echo pulse
rawDist = rawDist */ Scale ’ convert to uS
rawDist = rawDist / 2 ’ remove return trip
RETURN
'=======================================================================