Skip to content

Instantly share code, notes, and snippets.

@bouchtaoui-dev
Created October 31, 2018 20:53
Show Gist options
  • Select an option

  • Save bouchtaoui-dev/0780f5c37d82d5f773b5d42e9b92a46c to your computer and use it in GitHub Desktop.

Select an option

Save bouchtaoui-dev/0780f5c37d82d5f773b5d42e9b92a46c to your computer and use it in GitHub Desktop.
#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