Skip to content
Snippets Groups Projects
Commit 10b51933 authored by Kasalehlia's avatar Kasalehlia
Browse files

Merge branch 'master' into 'master'

bewegungsmelderskript und systemd-service hinzugefuegt

See merge request !2
parents d4336bc2 3683195a
No related branches found
No related tags found
1 merge request!2bewegungsmelderskript und systemd-service hinzugefuegt
#!/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()
[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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment