-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotion.c
More file actions
42 lines (33 loc) · 894 Bytes
/
motion.c
File metadata and controls
42 lines (33 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/******************************************************************************
Program: Motion detector
This example program shows the use of motion sensor to detect
movement/motion
Hardware: CrowPi (with Raspberry Pi 3B+)
Software: Raspbian system with WiringPi library
Compile: $ gcc -o motion motion.c -lwiringPi -Wall
Run with: $ ./motion
Jan 2020
******************************************************************************/
#include <stdio.h>
#include <wiringPi.h>
#define MOTIONSENSOR 16
int main()
{
// Setup
wiringPiSetupPhys();
pinMode(MOTIONSENSOR, INPUT);
// Instruction
printf("Wave your hand above the motion sensor.\n");
printf("Press Ctrl-C to END.\n");
// Main loop
while(1) {
if( digitalRead(MOTIONSENSOR) ) {
printf("Motion detected!\r");
}
else {
printf(" \r");
}
delay(10);
}
return 0;
}