intial import from article

This commit is contained in:
2019-07-31 20:02:36 +02:00
commit a46da2a8bf
3 changed files with 99 additions and 0 deletions

51
smartmirror_ir.py Normal file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env python
import RPi.GPIO as GPIO
import os
import time
import sys
# PIR pin
PIR_GPIO = 16
# Display timeout in seconds
TIMEOUT = 60
# DONT EDIT BELOW THIS LINE
# UNLESS YOU KNOW WHAT YOU ARE DOING
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIR_GPIO, GPIO.IN)
timer = 0
display = False
def set_display(enable):
global display
display = enable
os.system("vcgencmd display_power " + str(int(enable)))
def check_timeout():
if timer >= TIMEOUT and display:
set_display(False)
elif not display and timer < TIMEOUT:
set_display(True)
def motion(pin):
global timer
timer = 0
if __name__ == "__main__":
try:
GPIO.add_event_detect(PIR_GPIO, GPIO.RISING, callback=motion)
while True:
time.sleep(1)
if timer < TIMEOUT:
timer += 1
check_timeout()
except KeyboardInterrupt:
GPIO.cleanup()
sys.exit(0)