doorbuzz/shutdownbutton.py

25 lines
564 B
Python
Raw Normal View History

2016-04-01 00:37:54 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
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:
print "waiting..."
2016-03-10 20:25:13 +01:00
os.system('logger shutdownbutton waiting for press...')
2016-04-01 00:37:54 +02:00
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")
2016-04-01 00:37:54 +02:00
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
GPIO.cleanup() #