Code: Select all
import RPi.GPIO as GPIO
import os
import time
import Tkinter
import tkMessageBox
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16,GPIO.IN, pull_up_down=GPIO.PUD_DOWN
try:
while True:
if(GPIO.input(16)==1):
time.sleep(2);os.system("sudo shutdown -h now")
else:
#not necessary but added to show the program is alive
time.sleep(15);print("On")
except KeyboardInterrupt:
GPIO.cleanup();window=Tkinter.Tk();window.wm_withdraw();tkMessageBox.showinfo(title="Warning", message="Shutdown Program has been halted")A) My GPIO pin got messed up or
B) My code has something wrong