Advertisement
Yahmez

neszero.py

Mar 22nd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import RPi.GPIO as GPIO
  4. import os, time
  5.  
  6. GPIO.setmode(GPIO.BCM)
  7. GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)    #Low Voltage
  8. GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)   #Momentary power switch
  9. GPIO.setup(22, GPIO.OUT)                            #ON control
  10. GPIO.output(22, GPIO.HIGH)
  11.  
  12. while True:
  13.   if (GPIO.input(4)):
  14.     time.sleep(0.25)
  15.   else:
  16.     print ("Low Battery! Shutting down...")
  17.     time.sleep(3)
  18.     os.system("sudo shutdown -h now")
  19.   if (GPIO.input(17)):
  20.     time.sleep(3)
  21.     if (GPIO.input(17)):
  22.       print ("Shutting Down...")
  23.       os.system("sudo shutdown -h now")
  24.   else:
  25.     time.sleep(0.25)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement