PING))) documentation v1.5

Copyright © Parallax Inc. PING))) Ultrasonic Distance Sensor (#28015) v1.5 2/15/2008 Page 7 of 12
Example Program: PingMeasureCmAndIn.bs2
This example BS2 program is an excerpt from Chapter 2 of the Stamps in Class text
Smart Sensors and
Applications
. Additional PBASIC programs, one for the BS1 and another than runs on any model of
BASIC Stamp 2 (BS2, BS2e, BS2sx, BS2p, BS2pe, BS2px) can be downloaded from the 28015 product
page.
' 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