commit 58c2817f44f94362bb54be225266feedac33c35b Author: Daniel Kluge Date: Sat Oct 16 19:08:32 2021 +0200 First script diff --git a/motion.c b/motion.c new file mode 100644 index 0000000..e192a02 --- /dev/null +++ b/motion.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#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); + } +} +