PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Sensor
PIR Motion
PIR Rev B.c
1
/*
2
PIR Rev B.c
3
4
http://learn.parallax.com/propeller-c-simple-devices/pir-motion-sensor
5
6
Connect:
7
OUT to P5
8
VCC to 3.3V
9
GND to GND
10
11
The PIR sensors OUT pin sends a high signal for several seconds if motion is detected.
12
This output is copied to a variable named state with the statement: state = input(5).
13
The state variable will store 1 if motion has been detected recently, or 0 if it has
14
not. Detected output (state = 1) takes several seconds to clear after motion event
15
is over.
16
*/
17
18
#include "
simpletools.h
"
// Include simpletools library
19
20
int
main
()
// Main function
21
{
22
while
(1)
// Main loop
23
{
24
int
state =
input
(5);
// Check sensor (1) motion, (0) no motion
25
print
(
"%c state = %d%c\n"
,
// Display sensor
26
HOME
, state,
CLREOL
);
27
pause
(200);
// Pause 1/5 second before repeat
28
}
29
}
30
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