1

I'm trying to make an arcade cabinet with my Raspberry Pi and I want to make a physical shutdown button for it. I can do this with the GPIO, I even wrote a python script to do it:

import RPi.GPIO as GPIO
import time
import os

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_UP)
while True:
    print GPIO.input(17)
    if(GPIO.input(17) == False):
        os.system("sudo shutdown -h now")
        break
    time.sleep(1)

I have a switch connected to GRD and to PIN17, that way when I press the button it shutdowns. The problem is I want the script to be running 24/7 so that whenever I push the button it shutdowns! How can I do that?

Note: I'm running RetroPie

  • 2
    Just have it start a bootup. Just reference it inside /etc/rc.local by adding something like /home/pi/yourscript.py – Gerben Apr 6 '14 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.