documentation v1.0

Copyright © Parallax Inc. Sound Impact Sensor (#29132) v1.0 10/27/2009 Page 2 of 2
Source Code
These programs are available from the Sound Impact Sensor product page. Browse to www.parallax.com
and “Search” for 29132.
BASIC Stamp
®
2 Program
This program will display the current state of the output pin from the Sound Impact Sensor connected to
P0 using the Debug Terminal included in the BASIC Stamp Editor software, available for download from
www.parallax.com/basicstampsoftware
.
' {$STAMP BS2}
' {$PBASIC 2.5}
DO
IF IN0 = 1 THEN ' When noise detected, display
DEBUG HOME, "Sound detected!", CLREOL ' a message
PAUSE 1000
ELSE ' If no sound is detected,
DEBUG HOME,"All is well", CLREOL ' display that all is well.
ENDIF
PAUSE 10 ' Short delay
LOOP ' Repeat
Propeller
P8X32A Application
This program will display the current state of the output pin from the Sound Impact Sensor connected to
P0 using the Parallax Serial Terminal. Note: This application uses the Parallax Serial Terminal.spin object
for displaying the state of the sensor. This object as well as the Parallax Serial Terminal itself is installed
with the Propeller Tool v1.2.6 which is available from the Downloads link at www.parallax.com/Propeller
.
{{ SoundImpactSensor_Simple.spin
Displays the current state of the output pin from the Sound Impact Sensor connected to P0
using the Parallax Serial Terminal. For P8X32A. }}
CON
_clkmode = xtal1 + pll16x ' System clock 80 MHz
_xinfreq = 5_000_000
OBJ
pst : "Parallax Serial Terminal"
PUB Main
dira[0]~ ' Set pin 0 to input
pst.Start(115_200) ' Set Parallax Serial Terminal to 115,200 baud
repeat
if ina[0] == 1
pst.Str(string("Sound detected!")) ' When noise is detected, display a message
waitcnt(clkfreq + cnt) ' Wait 1 second
pst.Clear ' Clear the Parallax Serial Terminal
else
pst.Str(string("All is well.")) ' If no sound detected, display all is well
waitcnt(clkfreq/10 + cnt) ' Wait 1/10 of a second
pst.Home ' Move cursor to the top left corner of the PST