Created
August 28, 2017 08:47
-
-
Save aallan/c2578d33082f124c6d7049d37fc4ed08 to your computer and use it in GitHub Desktop.
Shutdown code from http://hackaday.com/2017/05/30/diy-google-aiy/
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
#!/bin/python | |
# Script for shutting down the Raspberry Pi by pressing a button. | |
# by Inderpreet Singh (30 May 2017) | |
# http://hackaday.com/2017/05/30/diy-google-aiy/ | |
import RPi.GPIO as GPIO | |
import time | |
import os | |
# Use the Broadcom SOC Pin numbers | |
# Setup the Pin with Internal pullups enabled and PIN in reading mode. | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(02, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
# Our function on what to do when the button is pressed | |
def Shutdown(channel): | |
os.system(“sudo shutdown -h now”) | |
# Add our function to execute when the button pressed event happens | |
GPIO.add_event_detect(02, GPIO.FALLING, callback = Shutdown, bouncetime = 2000) | |
# Now wait! | |
while 1: | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment