Last active
May 7, 2020 05:34
-
-
Save MoritzBuetzer/294d6d08d60673faddf53a4a26e22dea to your computer and use it in GitHub Desktop.
RaspberryPi Shutdown Script
This file contains 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
# Add following line to /etc/rc.local | |
python /home/pi/scripts/shutdown.py & |
This file contains 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 | |
# Connect switch to Pin 5 and 6 | |
import RPi.GPIO as GPIO | |
import time | |
import subprocess | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(5, GPIO.IN) | |
oldButtonState = True | |
while True: | |
buttonState = GPIO.input(5) | |
if buttonState != oldButtonState and buttonState == False: | |
subprocess.call("shutdown -h now", shell=True, | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
oldButtonState = buttonState | |
time.sleep(.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment