Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/usr/bin/python
  2. import RPi.GPIO as GPIO
  3. import time
  4. import subprocess
  5.  
  6. # we will use the pin numbering to match the pins on the Pi, instead of the
  7. # GPIO pin outs (makes it easier to keep track of things)
  8.  
  9. GPIO.setmode(GPIO.BOARD)
  10.  
  11. # use the same pin that is used for the reset button (one button to rule them all!)
  12. GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  13.  
  14. oldButtonState1 = True
  15.  
  16. while True:
  17. #grab the current button state
  18. buttonState1 = GPIO.input(5)
  19.  
  20. # check to see if button has been pushed
  21. if buttonState1 != oldButtonState1 and buttonState1 == False:
  22. subprocess.call("shutdown -h now", shell=True,
  23. stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  24. oldButtonState1 = buttonState1
  25.  
  26. time.sleep(.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement