28029 Parallax Inc, 28029 Datasheet - Page 76

KIT PARTS SMART SENSORS W/TEXT

28029

Manufacturer Part Number
28029
Description
KIT PARTS SMART SENSORS W/TEXT
Manufacturer
Parallax Inc
Datasheet

Specifications of 28029

Accessory Type
Parts Kit
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
BASIC Stamp® or Javelin Modules
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Other names
28029PAR
Page 64 · Smart Sensors and Applications
P2. Example solution:
LOOP
' Smart Sensors and Applications - Ch2_Project2.bs2
' Make a sound when someone passes through the doorway.
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[ I/O Definitions ]---------------------------------------------
Ping
Speaker
' -----[ Constants ]---------------------------------------------------
InConstant
Doorjamb
' -----[ Variables ]---------------------------------------------------
inDistance
time
counter
' -----[ Main Routine ]------------------------------------------------
DO
LOOP
' -----[ Subroutines ] ------------------------------------------------
Read_Ping:
Sound_Alarm:
Calc_Distance:
PULSIN 15, 1, time
cmDistance = cmConstant ** time
SEROUT LCD, 84, [128, DEC3 cmDistance, " cm"]
IF cmDistance >= MaxDistance THEN HIGH LED
PAUSE 100
GOSUB Read_Ping
GOSUB Calc_Distance
IF (inDistance < Doorjamb) THEN
ENDIF
PULSOUT 15, 5
PULSIN 15, 1, time
RETURN
FREQOUT Speaker, 300, 3300
PAUSE 50
FREQOUT Speaker, 450, 2200
RETURN
inDistance = inConstant ** time
RETURN
GOSUB Sound_Alarm
PIN
PIN
CON
CON
VAR
VAR
VAR
15
9
890
35
Word
Word
Nib
' Read echo time
' Calculate distance from time
' Parallax Ping))) sensor
' Optional speaker
' Doorway width is 35 inches
' Round trip echo time
' Start Ping)))
' Read echo time
' Bing
' Bong
' These are the whole measurements
' Print distance on
' LCD scrn
' Toggle LED if out
' of range

Related parts for 28029