rm-hull / luma.led_matrix

Python module to drive LED Matrices & 7-segment displays (MAX7219) and RGB NeoPixels (WS2812 / APA102)
https://luma-led-matrix.readthedocs.io
MIT License
520 stars 157 forks source link

Question: device.set_byte in new luma / Migrating old code to luma #258

Closed sysmatt closed 2 years ago

sysmatt commented 2 years ago

Hi, I am rewriting some code based on the older max7219 0.2.3 and trying to migrate to luma.
In my code i called device.set_byte() to directly set col/row outputs. Is there a proper way to do this in Luma ?

I am not finding a direct replacement, but perhaps there is a data structure i can manipulate then call device.show() ?

Thanks! -Matt

rm-hull commented 2 years ago

Have a look at the example here: https://luma-led-matrix.readthedocs.io/en/latest/python-usage.html#x8-led-matrices

When you call with canvas() as draw: it gives you a Pillow image draw object, so you can use any methods that object offer, so instead of draw.rectangle, you could call draw.point e.g. https://pillow.readthedocs.io/en/stable/reference/ImageDraw.html#PIL.ImageDraw.ImageDraw.point

within the with block, you can call draw.point several times (or in a loop, or whatever), and as soon as the with block completes it will render the drawing instructions and flush to the display