Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding getPixelColor for the grid based coordination #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion Adafruit_WS2801.cpp
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
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