PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Learn
Examples
Devices
Sensor
Sound Impact
SoundImpactSensor StateMachine.c
1
/*
2
SoundImpactSensor StateMachine.c
3
4
Expands on "SondImpactSensor Simple" by remembering the previous state of
5
the sound impact sensor's output.
6
7
Connect: SIG to (R = 2.2 k) to P4, 5V to 5V, GND to GND
8
9
http://www.parallax.com/product/29132
10
*/
11
12
#include "simpletools.h"
// Include simpletools
13
14
int
p4 = 0, p4old = 1;
// Current & previous states
15
16
int
main
()
// Main function
17
{
18
while
(1)
// Main loop
19
{
20
int
p4 = input(4);
// Check sensor
21
if
(p4 != p4old)
// If state changed
22
{
23
if
(p4 == 1)
// and if state is 1 (detected)
24
{
25
print(
"Sound detected! \n"
);
// Display message and wait
26
pause(500);
27
}
28
else
// If state 0 (not detected)
29
{
30
print(
"Waiting for sound... \n"
);
// Display waiting...
31
}
32
}
33
p4old = p4;
// Save old state before repeat
34
}
35
}
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12