Skip to content

Commit

Permalink
microsoft#30 returns an array containing RGB+ values of a pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
CDEguia committed Nov 3, 2024
1 parent 9ef28dd commit 109a2a0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions neopixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 109a2a0

Please sign in to comment.