First script
This commit is contained in:
commit
58c2817f44
48
motion.c
Normal file
48
motion.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <unistd.h>
|
||||
#include <wiringPi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MOTION_PIN 0
|
||||
#define SECONDS_TO_OFF 30 //10*60
|
||||
|
||||
int pin_read = 0;
|
||||
int state = 1;
|
||||
int counter = 0;
|
||||
|
||||
int main(){
|
||||
wiringPiSetup();
|
||||
pinMode(MOTION_PIN, INPUT);
|
||||
while(1){
|
||||
pin_read = digitalRead(MOTION_PIN);
|
||||
//printf("%d\n",pin_read);
|
||||
|
||||
while(state && !pin_read){
|
||||
//printf("%d\n",counter);
|
||||
counter += 1;
|
||||
if(counter >= SECONDS_TO_OFF*2){
|
||||
printf("Turning off\n");
|
||||
system("tvservice -o");
|
||||
state = 0;
|
||||
}
|
||||
usleep(500*1000);
|
||||
pin_read = digitalRead(MOTION_PIN);
|
||||
}
|
||||
|
||||
if(!state && pin_read){
|
||||
printf("Turning on\n");
|
||||
system("tvservice -p");
|
||||
system("fbset -depth 8");
|
||||
usleep(50*1000);
|
||||
system("fbset -depth 16");
|
||||
usleep(50*1000);
|
||||
system("fbset -depth 24");
|
||||
usleep(50*1000);
|
||||
system("fbset -depth 32");
|
||||
state = 1;
|
||||
}
|
||||
counter = 0;
|
||||
usleep(500*1000);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user