Skip to content

Commit

Permalink
Move color565() from examples into Adafruit_Protomatter (not core)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaintYourDragon committed Oct 20, 2020
1 parent 7fd87fa commit db20821
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
16 changes: 3 additions & 13 deletions examples/doublebuffer/doublebuffer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ void setup(void) {
textY = matrix.height() / 2 - (y1 + h / 2); // Center text vertically

// Set up the colors of the bouncy balls.
ballcolor[0] = color565(0, 20, 0); // Dark green
ballcolor[1] = color565(0, 0, 20); // Dark blue
ballcolor[2] = color565(20, 0, 0); // ark red
ballcolor[0] = matrix.color565(0, 20, 0); // Dark green
ballcolor[1] = matrix.color565(0, 0, 20); // Dark blue
ballcolor[2] = matrix.color565(20, 0, 0); // ark red
}

// LOOP - RUNS REPEATEDLY AFTER SETUP --------------------------------------
Expand Down Expand Up @@ -174,13 +174,3 @@ void loop(void) {

delay(20); // 20 milliseconds = ~50 frames/second
}

// Utility function converts 24-bit color (8 bits red, green, blue) used in
// a lot of existing graphics code down to the "565" color format used by
// Adafruit_GFX. Might get further quantized by matrix if using less than
// 6-bit depth.
uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) {
return ((red & 0b11111000) << 8) |
((green & 0b11111100) << 3) |
( blue >> 3);
}
20 changes: 8 additions & 12 deletions examples/pixeldust/pixeldust.ino
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,14 @@ void setup(void) {
}
Serial.printf("%d total pixels\n", n);

colors[0] = color565(64, 64, 64); // Dark Gray
colors[1] = color565(120, 79, 23); // Brown
colors[2] = color565(228, 3, 3); // Red
colors[3] = color565(255,140, 0); // Orange
colors[4] = color565(255,237, 0); // Yellow
colors[5] = color565( 0,128, 38); // Green
colors[6] = color565( 0, 77,255); // Blue
colors[7] = color565(117, 7,135); // Purple
}

uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) {
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
colors[0] = matrix.color565(64, 64, 64); // Dark Gray
colors[1] = matrix.color565(120, 79, 23); // Brown
colors[2] = matrix.color565(228, 3, 3); // Red
colors[3] = matrix.color565(255,140, 0); // Orange
colors[4] = matrix.color565(255,237, 0); // Yellow
colors[5] = matrix.color565( 0,128, 38); // Green
colors[6] = matrix.color565( 0, 77,255); // Blue
colors[7] = matrix.color565(117, 7,135); // Purple
}

// MAIN LOOP - RUNS ONCE PER FRAME OF ANIMATION ----------------------------
Expand Down
25 changes: 8 additions & 17 deletions examples/simple/simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -145,35 +145,26 @@ void setup(void) {
// Make four color bars (red, green, blue, white) with brightness ramp:
for(int x=0; x<matrix.width(); x++) {
uint8_t level = x * 256 / matrix.width(); // 0-255 brightness
matrix.drawPixel(x, matrix.height() - 4, color565(level, 0, 0));
matrix.drawPixel(x, matrix.height() - 3, color565(0, level, 0));
matrix.drawPixel(x, matrix.height() - 2, color565(0, 0, level));
matrix.drawPixel(x, matrix.height() - 1, color565(level, level, level));
matrix.drawPixel(x, matrix.height() - 4, matrix.color565(level, 0, 0));
matrix.drawPixel(x, matrix.height() - 3, matrix.color565(0, level, 0));
matrix.drawPixel(x, matrix.height() - 2, matrix.color565(0, 0, level));
matrix.drawPixel(x, matrix.height() - 1,
matrix.color565(level, level, level));
}
// You'll notice the ramp looks smoother as bit depth increases
// (second argument to the matrix constructor call above setup()).

// Simple shapes and text, showing GFX library calls:
matrix.drawCircle(12, 10, 9, color565(255, 0, 0)); // Red
matrix.drawRect(14, 6, 17, 17, color565(0, 255, 0)); // Green
matrix.drawTriangle(32, 9, 41, 27, 23, 27, color565(0, 0, 255)); // Blue
matrix.drawCircle(12, 10, 9, matrix.color565(255, 0, 0));
matrix.drawRect(14, 6, 17, 17, matrix.color565(0, 255, 0));
matrix.drawTriangle(32, 9, 41, 27, 23, 27, matrix.color565(0, 0, 255));
matrix.println("ADAFRUIT"); // Default text color is white

// AFTER DRAWING, A show() CALL IS REQUIRED TO UPDATE THE MATRIX!

matrix.show(); // Copy data to matrix buffers
}

// Utility function converts 24-bit color (8 bits red, green, blue) used in
// a lot of existing graphics code down to the "565" color format used by
// Adafruit_GFX. Might get further quantized by matrix if using less than
// 6-bit depth.
uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) {
return ((red & 0b11111000) << 8) |
((green & 0b11111100) << 3) |
( blue >> 3);
}

// LOOP - RUNS REPEATEDLY AFTER SETUP --------------------------------------

void loop(void) {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit Protomatter
version=1.0.7
version=1.0.8
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=A library for Adafruit RGB LED matrices.
Expand Down
15 changes: 15 additions & 0 deletions src/Adafruit_Protomatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ class Adafruit_Protomatter : public GFXcanvas16 {
*/
uint32_t getFrameCount(void);

/*!
@brief Converts 24-bit color (8 bits red, green, blue) used in a lot
a lot of existing graphics code down to the "565" color format
used by Adafruit_GFX. Might get further quantized by matrix if
using less than 6-bit depth.
@param red Red brightness, 0 (min) to 255 (max).
@param green Green brightness, 0 (min) to 255 (max).
@param blue Blue brightness, 0 (min) to 255 (max).
@return Packed 16-bit (uint16_t) color value suitable for GFX drawing
functions.
*/
uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) {
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
}

private:
Protomatter_core core; // Underlying C struct
void convert_byte(uint8_t *dest); // GFXcanvas16-to-matrix
Expand Down

0 comments on commit db20821

Please sign in to comment.