A customisable delay that you can use to reset the strip (or omit if you don't need it)
main
benevpi 2021-01-25 15:14:23 +00:00
rodzic e7babd9915
commit 7513b599c3
2 zmienionych plików z 11 dodań i 2 usunięć

Wyświetl plik

@ -2,7 +2,10 @@ import time
from ws2812b import ws2812b
num_leds = 30
pixels = ws2812b(num_leds, 0,0)
pixels = ws2812b(num_leds, 0,0, delay=0)
pixels.fill(10,10,10)
pixels.show()
while True:
for i in range(num_leds):

Wyświetl plik

@ -16,12 +16,16 @@ def ws2812():
nop() .side(0) [T2 - 1]
wrap()
#delay here is the reset time. You need a pause to reset the LED strip back to the initial LED
#however, if you have quite a bit of processing to do before the next time you update the strip
#you could put in delay=0 (or a lower delay)
class ws2812b:
def __init__(self, num_leds, state_machine, pin):
def __init__(self, num_leds, state_machine, pin, delay=0.001):
self.pixels = array.array("I", [0 for _ in range(num_leds)])
self.sm = rp2.StateMachine(state_machine, ws2812, freq=8000000, sideset_base=Pin(pin))
self.sm.active(1)
self.num_leds = num_leds
self.delay = delay
def set_pixel(self, pixel_num, red, green, blue):
self.pixels[pixel_num] = blue | red << 8 | green << 16
@ -29,9 +33,11 @@ class ws2812b:
def show(self):
for i in range(self.num_leds):
self.sm.put(self.pixels[i],8)
time.sleep(self.delay)
def fill(self, red, green, blue):
for i in range(self.num_leds):
self.set_pixel(i, red, green, blue)
time.sleep(self.delay)