Created
July 5, 2018 12:23
-
-
Save flowolf/d4b6c57f0a0e036a6d05acb51a0b385a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
import RPi.GPIO as GPIO | |
import time | |
import subprocess | |
GPIO.setmode(GPIO.BOARD) | |
# we will use the pin numbering to match the pins on the Pi, instead of the | |
# GPIO pin outs (makes it easier to keep track of things) | |
# use the same pin that is used for the reset button (one button to rule them all!) | |
GPIO.setup(5, GPIO.IN) | |
oldButtonState1 = True | |
while True: | |
#grab the current button state | |
buttonState1 = GPIO.input(5) | |
# check to see if button has been pushed | |
if buttonState1 != oldButtonState1 and buttonState1 == False: | |
# shutdown | |
subprocess.call("shutdown -h now", shell=True, | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
oldButtonState1 = buttonState1 | |
time.sleep(.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment