#!/usr/bin/env python3 from subprocess import call import RPi.GPIO as GPIO from time import sleep PinSeven = 7 # GPIO 4 (Pin Seven) PinEight = 11 # GPIO 17 (Pin Eight) GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.cleanup() GPIO.setup(PinSeven, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(PinEight, GPIO.OUT, initial=1) try: while True: if GPIO.input(PinSeven) == GPIO.HIGH: sleep(0.1) sleep(2) if GPIO.input(PinSeven) == False: sleep(1) GPIO.output(PinEight, 0) call('poweroff', shell=False) else: call('reboot', shell=False) break except Exception as e: #print("Error occurred: {}".format(e)) GPIO.cleanup() finally: GPIO.cleanup()