This blog is a record of what I do, what I think and what I read. If you are interested to know about my professional experience, you can refer to the other blog of mine. http://admi2camac.blogspot.com/
Saturday, 4 March 2023
Loads of leds (random display)
from picozero import LED
from time import sleep as zzz
from random import randint
#max of 16 LEDs if using picozero, due to PWM conflicts.
#Using 0 to 15 to make setup easier
num_leds = 8
overflow_num=2**num_leds
leds=[]
for i in range(0,num_leds):
leds.append(LED(i))
#shuffle LEDs
for j in range(num_leds):
i=randint(1,num_leds-1)
leds[j],leds[i]=leds[i],leds[j]
#reverse the order of i and j
try:
while True:
i=randint(0,overflow_num)
for j, led in enumerate(leds):
led.brightness=int(bin(i+overflow_num)[j+3])
zzz(3)
except KeyboardInterrupt:
for led in leds:
led.off()
print('Turn off LEDs and quit')
#https://www.youtube.com/watch?v=9MZGQmkeLAA
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment