|
Kyle... here is the code hope this help
I'm answering my own post :)
' -----[ I/O Definitions ]-------------------------------------------------
Ping CON P15
' -----[ Constants ]-------------------------------------------------------
Trigger CON 10 RawToIn CON 73.746 RawToCm CON 29.034
' -----[ Variables ]-------------------------------------------------------
rawDist VAR Word ' raw measurement inches VAR Long cm VAR Long
' -----[ Program Code ]----------------------------------------------------
Main: GOSUB Get_Sonar ' get sensor value inches = float rawDist FDIV float RawToIn ' convert to inches cm = float rawDist FDIV float RawToCm ' convert to centimeters'' GOSUB Display 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.
Display: SEROUT S_OUT, I9600, [0, "Parallax Ping Sonar "] SEROUT S_OUT, I9600, [13, "====================="] SEROUT S_OUT, I9600, [13, "Time (uS)..... ", dec rawDist] SEROUT S_OUT, I9600, [13, "Inches........ ", real inches] SEROUT S_OUT, I9600, [13, "Centimeters... ", real cm] RETURN
Get_Sonar: HIGH Ping ' make trigger 0-1-0 PULSOUT Ping, Trigger ' activate sensor PULSIN Ping, 1, rawDist ' measure echo pulse rawDist = rawDist / 2 ' remove return trip RETURN
|