pxt-neopixel
pxt-neopixel copied to clipboard
No way to query color of a specific pixel
Unlike pxt-common-packages, there's no way to query a color of a specific pixel.
"In circuit playground, you have a block "pixel color at 0" which returns the colour of that light. Is this block available in micro:bit for strips that you add on? e,g. I want to know what colour light 4 is in my RGB strip?"
User request: https://twitter.com/LMcUnderwood/status/1006204237834018816
In Java it would look like
function getLedValues (led: number) {
// Get the current values for all leds
let current_buff = strip.buf
// Break up the buffer into chunks, each corresponding to an LED
let chunked_buff = current_buff.chunked(3)
// Get the Value requested
let current_value = chunked_buff.get(led)
// ENHANCEMENT: Return in different/requested format
// Returns: array of [green],[red],[blue] values, but could also return an int, string, or ...
return current_value.toArray(NumberFormat.UInt8LE)
}```