Guest User

Untitled

a guest
Dec 26th, 2015
314
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. import RPi.GPIO as g
  4. from time import sleep
  5. from subprocess import Popen
  6.  
  7. g.setmode(g.BCM)
  8. g.setup(26,g.IN)
  9.  
  10. def p26_callback(channel):
  11. command = ['/usr/bin/sudo','poweroff']
  12. Popen(command)
  13. g.remove_event_detect(channel) # we've done it once, stop watching
  14. return
  15.  
  16. g.add_event_detect(26, g.FALLING, callback=p26_callback)
  17.  
  18. try:
  19. sleep(30)
  20. finally:
  21. g.cleanup()
RAW Paste Data