-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshutdown.py
36 lines (32 loc) · 1.63 KB
/
shutdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# ===========================================================================
# Shut Down or Reset button for Raspberry Pi B+ (40 GPIO pins) #
# Requires RPi.GPIO Python class #
# https://pypi.python.org/pypi/RPi.GPIO #
# #
# Used pins marked with star (*): #
# * * #
# 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 #
# | | | | | | | | | | | | | | | | | | | | #
# ---------------------------------------------------------- #
# | | | | | | | | | | | | | | | | | | | | #
# 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 #
# #
# ===========================================================================
# Import the libraries to use time delays, send os commands and access GPIO pins
import RPi.GPIO as GPIO
from time import sleep
import os
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) # Turn off warnings output
GPIO.setup(38, GPIO.OUT) # Set pin #38 (GPIO20) to output
GPIO.setup(40, GPIO.IN) # Set pin #40 (GPIO21) to input
while True:
buttonIn = GPIO.input(40)
if buttonIn == True:
print 'System shuts down'
GPIO.cleanup()
#os.system("sudo reboot")
os.system("sudo shutdown -h now")
break
sleep(1)