diff --git a/examples/doublebuffer/doublebuffer.ino b/examples/doublebuffer/doublebuffer.ino index e0bd2c1..5dd5394 100644 --- a/examples/doublebuffer/doublebuffer.ino +++ b/examples/doublebuffer/doublebuffer.ino @@ -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 -------------------------------------- @@ -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); -} diff --git a/examples/pixeldust/pixeldust.ino b/examples/pixeldust/pixeldust.ino index 32143fc..0fa4126 100644 --- a/examples/pixeldust/pixeldust.ino +++ b/examples/pixeldust/pixeldust.ino @@ -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 ---------------------------- diff --git a/examples/simple/simple.ino b/examples/simple/simple.ino index a8b3141..07f6eea 100644 --- a/examples/simple/simple.ino +++ b/examples/simple/simple.ino @@ -145,18 +145,19 @@ void setup(void) { // Make four color bars (red, green, blue, white) with brightness ramp: for(int x=0; x> 3); -} - // LOOP - RUNS REPEATEDLY AFTER SETUP -------------------------------------- void loop(void) { diff --git a/library.properties b/library.properties index 480f515..322c3d8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit Protomatter -version=1.0.7 +version=1.0.8 author=Adafruit maintainer=Adafruit sentence=A library for Adafruit RGB LED matrices. diff --git a/src/Adafruit_Protomatter.h b/src/Adafruit_Protomatter.h index 195e00b..6fb26db 100644 --- a/src/Adafruit_Protomatter.h +++ b/src/Adafruit_Protomatter.h @@ -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