pi-power-button/listen-for-shutdown.py

13 lines
233 B
Python
Raw Normal View History

2017-05-10 16:05:53 +00:00
#!/usr/bin/env python
import RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
2017-05-10 16:05:53 +00:00
GPIO.wait_for_edge(3, GPIO.FALLING)
subprocess.call(['shutdown', '-h', 'now'], shell=False)