PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
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
}
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
input
int input(int pin)
Set an I/O pin to input and return 1 if pin detects a high signal, or 0 if it detects low.
Definition:
input.c:19
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17