Skip to content

Commit

Permalink
Sundry work in progress; color handling, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaintYourDragon committed Jul 7, 2013
1 parent 07dbd0b commit d7df760
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
20 changes: 15 additions & 5 deletions Adafruit_NeoMatrix.cpp
Expand Up @@ -20,11 +20,19 @@ Adafruit_NeoMatrix::Adafruit_NeoMatrix(uint8_t mW, uint8_t mH, uint8_t tX,
ledType), type(matrixType), matrixWidth(mW), matrixHeight(mH), tilesX(tX),
tilesY(tY), remapFn(NULL) { }

// Expand 16-bit input color to 24-bit colorspace
// Expand 16-bit input color (Adafruit_GFX colorspace) to 24-bit (NeoPixel)
// (w/gamma adjustment)
static uint32_t expandColor(uint16_t color) {
return (pgm_read_byte(&gamma5[ color >> 11 ]) << 16) |
(pgm_read_byte(&gamma6[(color >> 5) & 0x3F]) << 8) |
pgm_read_byte(&gamma5[ color & 0x1F]);
return ((uint32_t)pgm_read_byte(&gamma5[ color >> 11 ]) << 16) |
((uint32_t)pgm_read_byte(&gamma6[(color >> 5) & 0x3F]) << 8) |
pgm_read_byte(&gamma5[ color & 0x1F]);
}

// Downgrade 24-bit color to 16-bit (add reverse gamma lookup here?)
uint16_t Adafruit_NeoMatrix::Color(uint8_t r, uint8_t g, uint8_t b) {
return ((uint16_t)(r & 0x1f) << 11) |
((uint16_t)(g & 0x3f) << 5) |
(b >> 3);
}

void Adafruit_NeoMatrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
Expand All @@ -51,8 +59,9 @@ void Adafruit_NeoMatrix::drawPixel(int16_t x, int16_t y, uint16_t color) {

int i;

// LOTS OF MOJO STILL TO DO HERE
if(remapFn) {
// Custom remapping function
// Custom X/Y remapping function
i = (*remapFn)(x, y);
} else {
if(tilesX) {
Expand Down Expand Up @@ -95,3 +104,4 @@ void Adafruit_NeoMatrix::fillScreen(uint16_t color) {
void Adafruit_NeoMatrix::setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t)) {
remapFn = fn;
}

2 changes: 2 additions & 0 deletions Adafruit_NeoMatrix.h
Expand Up @@ -64,6 +64,8 @@ class Adafruit_NeoMatrix : public Adafruit_GFX, public Adafruit_NeoPixel {
drawPixel(int16_t x, int16_t y, uint16_t color),
fillScreen(uint16_t color),
setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t));
static uint16_t
Color(uint8_t r, uint8_t g, uint8_t b);

private:

Expand Down
28 changes: 13 additions & 15 deletions examples/matrixtest/matrixtest.pde
Expand Up @@ -8,33 +8,31 @@ Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 5, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);

const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };

void setup() {
Serial.begin(9600);
matrix.begin();
matrix.setRotation(3);
matrix.setTextWrap(false);
// matrix.setBrightness(40);
matrix.setTextColor(0x4000);
matrix.setBrightness(40);
matrix.setTextColor(colors[0]);
}

int x = 6;
int x = 6;
int pass = 0;

void loop() {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print("Hello");
if(--x < -36) x = 6;
matrix.print(F("Howdy"));
if(--x < -36) {
x = 6;
if(++pass >= 3) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(100);

/*
matrix.drawCircle(2, 2, 2, 0xF800);
matrix.show();
delay(1000);
matrix.drawCircle(2, 2, 2, 0x07E0);
matrix.show();
delay(1000);
matrix.drawCircle(2, 2, 2, 0x001F);
*/
}

0 comments on commit d7df760

Please sign in to comment.