#!/bin/python # Simple script for shutting down the raspberry Pi at the press of a button. # by Inderpreet Singh import RPi.GPIO as GPIO import time import os # Use the Broadcom SOC Pin numbers # Setup the Pin with Internal pullups enabled and PIN in reading mode. GPIO.setmode(GPIO.BCM) GPIO.setup(26, GPIO.IN, pull_up_down = GPIO.PUD_UP) # Our function on what to do when the button is pressed def Shutdown(): os.system("sudo shutdown -h now") lasttime = time.time() laststate = 1 # Add our function to execute when the button pressed event happens while 1: if laststate != GPIO.input(26): laststate = GPIO.input(26) lasttime = time.time() if laststate == 0 and lasttime+1< time.time(): Shutdown() time.sleep(0.05)