Created
October 31, 2018 20:53
-
-
Save bouchtaoui-dev/0780f5c37d82d5f773b5d42e9b92a46c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <wiringPi.h> | |
| #define LED 4 | |
| #define PIR 5 | |
| int main() { | |
| // doe een setup om wiringPi te gebruiken | |
| if(wiringPiSetup()<0) { | |
| printf("Error setting up wiringPi..."); | |
| return -1; | |
| } | |
| // configureer de gewenste pinnen | |
| pinMode( LED, OUTPUT ); | |
| pinMode( PIR, INPUT ); | |
| printf("Pin 4 is configured as output\n"); | |
| printf("Pin 5 is configured as input\n"); | |
| int duration = 1200; // 1200/50 = 60 sec. | |
| while(duration--) { | |
| // 1. check for motion | |
| delay(50); | |
| if(digitalRead(PIR)) { | |
| digitalWrite(LED, HIGH); | |
| int timeout = 6; | |
| int motion = HIGH; | |
| while( motion || timeout ) { | |
| motion = digitalRead(PIR); | |
| if(motion) | |
| timeout = 6; | |
| else | |
| timeout--; | |
| delay(1000); | |
| } | |
| digitalWrite(LED, LOW); | |
| } | |
| } | |
| digitalWrite(LED, 0); | |
| pinMode(LED, INPUT); | |
| printf("Program finished... thank you :)\n"); | |
| return 0; | |
| } | |
| 48,0-1 Bot | |
| 1,1 Top | |
| digitalWrite(LED, 0); | |
| pinMode(LED, INPUT); | |
| printf("Program finished... thank you :)\n"); | |
| return 0; | |
| } | |
| 48,0-1 Bot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment