This commit is contained in:
Minecon724 2024-05-14 18:42:12 +02:00
parent 4bc0cb7228
commit b670835081
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -3,8 +3,9 @@ from rp2 import PIO, StateMachine, asm_pio
from time import sleep_ms, sleep_us from time import sleep_ms, sleep_us
from random import randint from random import randint
LEDS = 3 LEDS = 5
PIN = Pin(16) PIN = Pin(16)
DELAY = 5
""" """
inspired by https://github.com/raspberrypi/pico-micropython-examples/blob/master/pio/pio_ws2812.py 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 = StateMachine(0, prog, sideset_base=PIN)
sm.active(1) 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: while True:
for i in range(LEDS): cols.pop(0)
sm.put(randint(0, 0xFFFFFF), 8) # I still don't know why 8 not 24 cols.append(cols_new[-1])
cols_new.pop(0)
sleep_ms(500) 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)