doorbuzz/shutdownbutton.py

22 lines
526 B
Python
Raw Permalink Normal View History

buttonpin=24
import RPi.GPIO as GPIO
import time
import os
2016-03-10 20:25:13 +01:00
GPIO.setmode(GPIO.BCM)
GPIO.setup(buttonpin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
2016-04-01 00:36:44 +02:00
print("waiting...")
2016-03-10 20:25:13 +01:00
os.system('logger shutdownbutton waiting for press...')
try:
GPIO.wait_for_edge(buttonpin, GPIO.FALLING)
print('Button Pressed')
2016-03-10 20:25:13 +01:00
os.system('logger shutdownbutton pressen. bye bye')
os.system("shutdown now -h")
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
GPIO.cleanup() #