Last active
August 15, 2017 20:26
-
-
Save jonwitts/85ab3b4ef0f75b11b1e8b037b0693edd to your computer and use it in GitHub Desktop.
A Python program to shutdown a Pi when button is held for 3 seconds
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/python3 | |
from gpiozero import Button, LED | |
from signal import pause | |
from time import sleep | |
from os import system | |
button = Button(21, hold_time=3) | |
led = LED(20) | |
def shutdown_pi(): | |
for i in range(3): | |
led.on() | |
sleep(0.5) | |
led.off() | |
sleep(0.5) | |
system("sudo shutdown now -hP") | |
button.when_held = shutdown_pi | |
pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment