I need to run some system commands on a button press. But after pressing the first button the script seams to stop working, it's not closing but doesn't react to any other button presses.
For test I wrote this script:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import os
buttonShutdown = 6
button9x9 = 13
buttonNext = 19
buttonPrev = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(buttonShutdown, GPIO.IN)
GPIO.setup(button9x9, GPIO.IN)
GPIO.setup(buttonNext, GPIO.IN)
GPIO.setup(buttonPrev, GPIO.IN)
GPIO.add_event_detect(buttonShutdown, GPIO.FALLING)
GPIO.add_event_detect(button9x9, GPIO.FALLING)
GPIO.add_event_detect(buttonNext, GPIO.FALLING)
GPIO.add_event_detect(buttonPrev, GPIO.FALLING)
while True:
if GPIO.event_detected(buttonShutdown):
cmd = "echo shutdown"
os.system(cmd)
if GPIO.event_detected(button9x9):
cmd = "echo 9x9"
os.system(cmd)
if GPIO.event_detected(buttonNext):
cmd = "echo next"
os.system(cmd)
if GPIO.event_detected(buttonPrev):
cmd = "echo prev"
os.system(cmd)
time.sleep(0.1)
Does anyone know why it seems to hang?