Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Adafruit_WS2801.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,28 @@ uint32_t Adafruit_WS2801::getPixelColor(uint16_t n) {
((uint32_t)pixels[ofs] << 16) | ((uint16_t) pixels[ofs + 1] << 8) | pixels[ofs + 2] :
(pixels[ofs] << 8) | ((uint32_t)pixels[ofs + 1] << 16) | pixels[ofs + 2];
}

return 0; // Pixel # is out of bounds
}
// Get pixel color from previously-set pixel (returns packed 32-bit RGB value) using x,y coordinate system:
uint32_t *Adafruit_WS2801::getPixelColor(uint16_t x, uint16_t y) {
static uint32_t result[3];
boolean evenRow = ((y % 2) == 0);
// calculate x offset first
uint16_t ofs = x % width;
if (!evenRow) {
ofs = (width-1) - ofs;
}
// add y offset
ofs += y * width;
result[0]=0;
result[1]=0;
result[2]=0;
if(ofs < numLEDs) {
ofs=ofs * 3;
result[0]=pixels[ofs];
result[1]=pixels[ofs+1];
result[2]=pixels[ofs+2];
}
return result;
}

2 changes: 2 additions & 0 deletions Adafruit_WS2801.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Adafruit_WS2801 {
numPixels(void);
uint32_t
getPixelColor(uint16_t n);
uint32_t *
getPixelColor(uint16_t x, uint16_t y);

private:

Expand Down