Aug-22-2022, 03:02 AM
(This post was last modified: Aug-22-2022, 03:02 AM by deanhystad.)
Instead of this:
for i in range(3): leds.on() buzzer.on() time.sleep(0.2) leds.off() buzzer.off()Do this:
for led in leds[:3]: # loop over the first three leds. led.on() buzzer.on() time.sleep(0.2) led.off() buzzer.off()Or this:
for i in range(3): leds[i].on() buzzer.on() time.sleep(0.2) leds[i].off() buzzer.off()Of the two I prefer the one that uses a slice instead of range(). If you want to iterate over a list of LED's why iterate over a range of numbers, then use the numbers to get the LEDs?