This is the code:
#!/usr/bin/python3 from time import sleep from gpiozero import LED, Button from threading import Thread from signal import pause, signal, SIGTERM LEDs = [5, 17, 22, 19, 26] LIGHTS = [LED(LEDs), LED(LEDs), LED(LEDs), LED(LEDs), LED(LEDs)] pushButton = Button(21) DELAY = 0.5 def cleanup(signum, frame): exit(2) # TODO: Create a button callback function which will change blinking speed def buttonLEDs(): global DELAY while True: if pushButton.is_pressed: print("Click") DELAY += 0.1 def LEDseq(): while True: for LED in LIGHTS: LED.on() sleep(DELAY) LED.off() for LED in reversed(LIGHTS): LED.on() sleep(DELAY) LED.off() try: signal(SIGTERM, cleanup) # pushButton = buttonControl # pushButton.when_pressed = LEDseq LEDseq() # buttonControl(LEDseq) pause() except KeyboardInterrupt: exit(1)
I'm trying to make a callback function for a button that would change the sleep interval of
LEDseq when the button is pressed so I created this function:
but it doesn't seem to work. Any idea why?