Skip to content

Instantly share code, notes, and snippets.

@tiagordc
Last active November 28, 2021 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagordc/8d1d02a2c3eed6e3ee038028e23ac97f to your computer and use it in GitHub Desktop.
Save tiagordc/8d1d02a2c3eed6e3ee038028e23ac97f to your computer and use it in GitHub Desktop.

Blink RPi leds randomly

from gpiozero import LED
from time import sleep
from random import choice

leds = [ LED(17), LED(18), 
         LED(24), LED(25), LED(5), LED(6), LED(16), 
         LED(23), LED(22), LED(12), LED(20), LED(19), 
         LED(4), LED(27), LED(21), LED(13), LED(26) ]

try:
    while True:
        led = choice(leds)
        led.toggle()
        sleep(0.01)
except KeyboardInterrupt:
    for led in leds:
        led.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment