-
-
Save justbill2020/e9adb3e2334ad5c05f42618a59a09673 to your computer and use it in GitHub Desktop.
Turns the hdmi port on and off by reading a PIR sensor off a raspberry pi GPIO port 11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
from threading import Timer | |
import subprocess | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(11, GPIO.IN) | |
timer = False | |
monitor_is_on = True | |
def monitor_off(): | |
global monitor_is_on | |
subprocess.call(['/opt/vc/bin/tvservice', '-o']) | |
monitor_is_on = False | |
def monitor_on(): | |
global monitor_is_on | |
subprocess.call(['/opt/vc/bin/tvservice', '-p']) | |
subprocess.call(['fbset -depth 8'], shell=True) | |
subprocess.call(['fbset -depth 16'], shell=True) | |
subprocess.call(['xrefresh'], shell=True) | |
monitor_is_on = True | |
while True: | |
time.sleep(0.5) | |
movement = GPIO.input(11) | |
if movement: | |
if timer: | |
print "canceler timer" | |
timer.cancel() | |
timer = False | |
if not monitor_is_on: | |
print "Taender skaerm" | |
monitor_on() | |
else: | |
if not timer: | |
print "starter timer" | |
timer = Timer(60*5, monitor_off) | |
timer.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment