KanoComputing / community-sdk

Scripts, tools and libraries to help you to interact with your Kano Devices in your favourite programming language.
MIT License
31 stars 10 forks source link

Setting colors for individual LEDs on Pixel Kit #15

Open murilopolese opened 5 years ago

murilopolese commented 5 years ago

In both implementations for "streaming frame" (python and nodejs), what the communitysdk does is to encode and send a list of 128 color values: One for each LED.

This list is a one dimensional representation of a two dimensional matrix of LEDs so to set the color of an LED by the x and y coordinate we need to convert a pair of coordinates (x, y) into an index in the unidimensional list.

The math is not complicated, for example if you want to set this color to red (#ff0000) all you have to do is to set a value in the frame array:

index = (x * 16) + y
frame[index] = '#ff0000'
# stream frame here

It would be great to have a method inside the communitysdk to solve this issue and/or an example on how to do this calculation.

mexitalian commented 5 years ago

Have started work on this, it is working with example included. Going to write the unit tests, would love some feedback. Can see changes to retailpixel.py → here