Copyright © Parallax Inc.
PING))) Ultrasonic Distance Sensor (#28015)
v2.0 2/4/2013 Page 7 of 9
Example Program: PingMeasureCmAndIn.bs2
This program for the BASIC Stamp 2 displays distance measurements in both inches and centimeters in
the BASIC Stamp Debug Terminal. The example program can be downloaded from the 28015 product
page at
www.parallax.com
. The BASIC Stamp Editor software, which includes the Debug Terminal, is a
free download from
www.parallax.com/basicstampsoftware
.
' Smart Sensors and Applications - PingMeasureCmAndIn.bs2
' Measure distance with Ping))) sensor and display in both in & cm
' {$STAMP BS2}
' {$PBASIC 2.5}
' Conversion constants for room temperature measurements.
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP