From 109a2a0632722d9e88e58f51e11420fb3028d47f Mon Sep 17 00:00:00 2001 From: CDEguia Date: Sun, 3 Nov 2024 14:44:07 -0800 Subject: [PATCH] #30 returns an array containing RGB+ values of a pixel --- neopixel.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/neopixel.ts b/neopixel.ts index dd8e8f7..a4dcd48 100644 --- a/neopixel.ts +++ b/neopixel.ts @@ -188,6 +188,21 @@ namespace neopixel { this.setPixelRGB(pixeloffset >> 0, rgb >> 0); } + /** + * Returns an array of RGB, GRB or RGBW values for the given pixel in a strip + * @param pixeloffset position of the NeoPixel in the strip + */ + //% blockId=neopixel_get_pixel_colors block="%strip|get pixel %pixel" + //% strip.defl=strip + //% blockGap=8 + //% weight=5 + //% parts="neopixel" advanced=true + getPixelColor(pixeloffset: number, ){ + if (pixeloffset < 0 || pixeloffset >= this._length) return []; + const stride = this._mode === NeoPixelMode.RGBW ? 4 : 3; + return this.buf.chunked(stride).get(pixeloffset).toArray(NumberFormat.UInt8LE) + } + /** * Sets the number of pixels in a matrix shaped strip * @param width number of pixels in a row