diff --git a/movement.py b/movement.py new file mode 100755 index 0000000000000000000000000000000000000000..eb5c934048f8a943b9b026bb6961ac3d5a6d5e8a --- /dev/null +++ b/movement.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import RPi.GPIO as GPIO +import time +from subprocess import call +GPIO.setmode(GPIO.BCM) + +GPIO.setup(4, GPIO.IN) +#GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) +print("works so far") + +pir = 4 +previous_state = 0 +current_state = 0 + +try: + while True: + time.sleep(0.1) + current_state = GPIO.input(pir) + if current_state == 1 and previous_state == 0: + print("GPIO pin %s is %s, turning screen on" % (pir, current_state)) + call("echo on 0 | cec-client -s -d 1", shell=True) + previous_state = 1 + elif current_state == 0 and previous_state == 1: + print("GPIO pin %s is %s, turning screen off" % (pir, current_state)) + call("echo standby 0 | cec-client -s -d 1", shell=True) + previous_state = 0 + time.sleep(0.01) + +except KeyboardInterrupt: + pass +finally: + GPIO.cleanup() diff --git a/pirscreencontrol.service b/pirscreencontrol.service new file mode 100644 index 0000000000000000000000000000000000000000..68acb96cfa94ee5abc3cad5c5d6881527fd94319 --- /dev/null +++ b/pirscreencontrol.service @@ -0,0 +1,11 @@ +[Unit] +Description=PIR Screen Control +After=multi-user.target + +[Service] +Type=idle +ExecStart=/usr/bin/python3 /home/pi/movement.py + +[Install] +WantedBy=multi-user.target +