PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Sensor
Sound Impact
SoundImpactSensor Simple.c
1
/*
2
SoundImpactSensor Simple.c
3
4
This sensor can be monitored repeatedly, and with a relatively small
5
interval to check for sounds. The sensor's SIG pin sends a high signal
6
if sound is detected, or a low if not. Since SIG is connected to P4,
7
input(4) will return 1 if detected, or 0 if not.
8
9
Connect: SIG to (R = 2.2 k) to P4, 5V to 5V, GND to GND
10
11
http://www.parallax.com/product/29132
12
*/
13
14
#include "
simpletools.h
"
// Include simpletools
15
16
int
main
()
// Main function
17
{
18
while
(1)
// Main loop
19
{
20
print
(
"%c"
,
HOME
);
// Cursor -> top-left
21
if
(
input
(4))
// Sensor high (detected)
22
{
23
print
(
"Sound impact detected!%c"
,
CLREOL
);
// Display detected message
24
pause
(1000);
// Wait for user to see it
25
}
26
else
// Sensor low (not detected)
27
{
28
print
(
"Waiting for sound...%c"
,
CLREOL
);
// Display waiting message
29
}
30
pause
(50);
// Slow down for terminal
31
}
32
}
HOME
#define HOME
HOME character (1) sends SimpleIDE Terminal's cursor to top-left "home" position.
Definition:
simpletools.h:233
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
CLREOL
#define CLREOL
CLREOL character (11) erases all SimpleIDE Terminal characters to the right of the cursor.
Definition:
simpletools.h:323
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17