Skip to content

Instantly share code, notes, and snippets.

@flowolf
Created July 5, 2018 12:23
Show Gist options
  • Select an option

  • Save flowolf/d4b6c57f0a0e036a6d05acb51a0b385a to your computer and use it in GitHub Desktop.

Select an option

Save flowolf/d4b6c57f0a0e036a6d05acb51a0b385a to your computer and use it in GitHub Desktop.

Revisions

  1. flowolf created this gist Jul 5, 2018.
    26 changes: 26 additions & 0 deletions shutdown.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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)