pxt-neopixel icon indicating copy to clipboard operation
pxt-neopixel copied to clipboard

No way to query color of a specific pixel

Open samelhusseini opened this issue 8 years ago • 1 comments

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

samelhusseini avatar Jun 11 '18 18:06 samelhusseini

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)
}```

CDEguia avatar Oct 31 '24 14:10 CDEguia