blaz-r / pi_pico_neopixel

Pi Pico library for NeoPixel led-strip written in MicroPython. Works with ws2812b (RGB) and sk6812 (RGBW).
MIT License
254 stars 54 forks source link

Add 'assign to slice' (__setitem__) method, plus various speed improvements #6

Closed gsmith-to closed 2 years ago

gsmith-to commented 2 years ago

This is a mostly a number of small changes to improve efficiency; and there are two 'feature adds':

I had looked for a way to pass a range of pixels to set_pixel, so that when calling set_pixel_line or fill, we could avoid the repeated calculation inside set_pixel; instead, just do it it once and store it multiple times. By making set_pixel accept a slice object for 'pixel_num', we get this advantage and can also implement the __setitem__ operation for assigning to slices, by just forwarding the slice to get_pixel.

The branch is a series of small, mostly independent mods (one per commit) to make it easier to review; and relatively easy to drop any you don't like.

NOTE: I have only tested with "GRB" mode, since that's what the LEDs I have are.

blaz-r commented 2 years ago

Amazing work! I tested with GRB and RGBW and it all seems to work. The improvement of efficiency is quite significant. Thanks a lot for all this. 😄