Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import RPi.GPIO as GPIO
- import os, time
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Low Voltage
- GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Momentary power switch
- GPIO.setup(22, GPIO.OUT) #ON control
- GPIO.output(22, GPIO.HIGH)
- while True:
- if (GPIO.input(4)):
- time.sleep(0.25)
- else:
- print ("Low Battery! Shutting down...")
- time.sleep(3)
- os.system("sudo shutdown -h now")
- if (GPIO.input(17)):
- time.sleep(3)
- if (GPIO.input(17)):
- print ("Shutting Down...")
- os.system("sudo shutdown -h now")
- else:
- time.sleep(0.25)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement