I have a python script working that will shutdown the raspberry pi when I close a momentary switch, using the RPi.GPIO interrupts. However as soon as the switch is closed the pi shuts down. Is there a way to program in a time function i.e. only shutdown the pi with the momentary switch is closed for 2 seconds? I am trying to avoid accidental bumps of the shutdown switch.
Here is my script:
import subprocess import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.wait_for_edge(17, GPIO.FALLING) subprocess.call(['shutdown -h now "System halted by GPIO action"'], shell=True) GPIO.cleanup()