Read Pixel Colour on Unicorn


#1

Can I find the colour value of a pixel - is the state of the matrix stored somewhere?

Simon


#2

Yes, it’s stored in a buffer in C. And I don’t believe I’ve exposed a “read” method- but it shouldn’t be too difficult to add one since I believe it’s already available in the ws2812 Python library which Unicornhat wraps.

If you clone the code from GitHub, find Unicornhat.py: https://github.com/pimoroni/UnicornHat/blob/master/python/UnicornHat/unicornhat.py

Then stick this after the set_pixel method:

def get_pixel(x, y,):
  index = get_index_from_xy(x, y)
  if index != None:
    return ws2812.getPixelColor(index)

Then install!

I’ll test this and get it into the library properly, anyway.


#3

BOOM!

https://github.com/pimoroni/UnicornHat/commit/4992bda307dad63043891e47c4d9a6376f57f229


#4

Ta very much
Simon
padding


#5

As requested by @ukscone I’ve added a get_pixels method for… well… getting all the pixels!

https://github.com/pimoroni/UnicornHat/commit/d21c31a0476c241a977548c8081bcafc819e7004