diff --git a/examples/flash.py b/examples/flash.py index 91b8d62..c70c9f3 100644 --- a/examples/flash.py +++ b/examples/flash.py @@ -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): diff --git a/ws2812b.py b/ws2812b.py index 8c23264..53ec58d 100644 --- a/ws2812b.py +++ b/ws2812b.py @@ -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) \ No newline at end of file