Guest User

Untitled

a guest
May 2nd, 2019
314
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import RPi.GPIO as GPIO
  2. import time
  3. import subprocess
  4. from threading import Timer
  5.  
  6. SHUTDOWN_HOLD_TIME = 5 # Time in seconds that power button must be held
  7. SHUTDOWN_PIN = 5 # Pin to trigger shutdown, pin 5 will also start up the pi when it's off
  8.  
  9. # GPIO.BOARD means use pin numbering to matching the pins on the Pi, instead of the
  10. # CPU's actual pin numbering (makes it easier to keep track of things)
  11. GPIO.setmode(GPIO.BOARD)
  12. GPIO.setup(SHUTDOWN_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  13.  
  14. buttonReleased = True
  15. while buttonReleased:
  16.     GPIO.wait_for_edge(SHUTDOWN_PIN, GPIO.FALLING)
  17.     # button has been pressed
  18.     buttonReleased = False
  19.     for i in range(SHUTDOWN_HOLD_TIME * 10):
  20.         time.sleep(0.1)
  21.         if GPIO.input(SHUTDOWN_PIN):
  22.             buttonReleased = True
  23.             break
  24.  
  25. GPIO.cleanup()
  26. subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×