You appear to be using gpiozero so a lot of the code can be handled for you. For the basics of a button controlled LED see https://gpiozero.readthedocs.io/en/stab ... rolled-led
I'd try something like this:The above is untested.
[edit]
Just FYI, the call to signal.pause() suspends your main thread without it exiting which avoids the need for an infinite loop. You can still use one instead or use one to do something entirely unrelated to the LEDs.
[/edit]
I'd try something like this:
Code:
import gpiozeroimport signalLEDS = [gpiozero.LED(17), gpiozero.LED(19)] # fill in the rest yourselfBUTTONS = [gpiozero.Button(9), gpiozero.Button(10)] # fill in the rest yourselffor i in range(0, len(LEDS)): # assumes both lists have the same number of entries i.source = BUTTONS[i}signal.pause()[edit]
Just FYI, the call to signal.pause() suspends your main thread without it exiting which avoids the need for an infinite loop. You can still use one instead or use one to do something entirely unrelated to the LEDs.
[/edit]
Statistics: Posted by thagrol — Mon May 18, 2026 11:48 pm









