improve
This commit is contained in:
parent
4bc0cb7228
commit
b670835081
1 changed files with 23 additions and 5 deletions
28
ws2811.py
28
ws2811.py
|
@ -3,8 +3,9 @@ from rp2 import PIO, StateMachine, asm_pio
|
|||
from time import sleep_ms, sleep_us
|
||||
from random import randint
|
||||
|
||||
LEDS = 3
|
||||
LEDS = 5
|
||||
PIN = Pin(16)
|
||||
DELAY = 5
|
||||
|
||||
"""
|
||||
inspired by https://github.com/raspberrypi/pico-micropython-examples/blob/master/pio/pio_ws2812.py
|
||||
|
@ -58,8 +59,25 @@ def prog():
|
|||
sm = StateMachine(0, prog, sideset_base=PIN)
|
||||
sm.active(1)
|
||||
|
||||
def transition_step(src_hex: int, tgt_hex: int, prog: float):
|
||||
src_hex += int(( (tgt_hex >> 16) - (src_hex >> 16) ) * prog) << 16
|
||||
src_hex += int(( (tgt_hex >> 8 & 0xFF) - (src_hex >> 8 & 0xFF) ) * prog) << 8
|
||||
src_hex += int(( (tgt_hex & 0xFF) - (src_hex & 0xFF) ) * prog)
|
||||
|
||||
return src_hex
|
||||
|
||||
cols = [randint(0, 0xFFFFFF) for i in range(LEDS)]
|
||||
cols_new = cols[1:] + [randint(0, 0xFFFFFF)]
|
||||
|
||||
while True:
|
||||
for i in range(LEDS):
|
||||
sm.put(randint(0, 0xFFFFFF), 8) # I still don't know why 8 not 24
|
||||
|
||||
sleep_ms(500)
|
||||
cols.pop(0)
|
||||
cols.append(cols_new[-1])
|
||||
cols_new.pop(0)
|
||||
cols_new.append(randint(0, 0xFFFFFF))
|
||||
|
||||
for i in range(0, 100):
|
||||
for l in range(LEDS):
|
||||
cold = transition_step(cols[l], cols_new[l], i / 100)
|
||||
sm.put(cold, 8) # I don't know why 8 not 24
|
||||
sleep_ms(DELAY)
|
||||
|
Loading…
Reference in a new issue