From 532f1d5cd292a940b75c5f877e8a35cdd826de02 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Thu, 6 Apr 2017 12:20:12 -0700 Subject: [PATCH 01/15] New demo. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 462 +++++++++++++++++++++++ 1 file changed, 462 insertions(+) create mode 100644 examples/MatrixGFXDemo/MatrixGFXDemo.ino diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino new file mode 100644 index 0000000..01726f9 --- /dev/null +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -0,0 +1,462 @@ +// Adafruit_NeoMatrix example for single NeoPixel Shield. +// By Marc MERLIN + +#include +#include +#include +#ifndef PSTR + #define PSTR // Make Arduino Due happy +#endif + +#define PIN 6 + +// MATRIX DECLARATION: +// Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display) +// Parameter 2 = height of each matrix +// Parameter 3 = number of matrices arranged horizontally +// Parameter 4 = number of matrices arranged vertically +// Parameter 5 = pin number (most are valid) +// Parameter 6 = matrix layout flags, add together as needed: +// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT: +// Position of the FIRST LED in the FIRST MATRIX; pick two, e.g. +// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner. +// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are +// arranged in horizontal rows or in vertical columns, respectively; +// pick one or the other. +// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns WITHIN +// EACH MATRIX proceed in the same order, or alternate lines reverse +// direction; pick one. +// NEO_TILE_TOP, NEO_TILE_BOTTOM, NEO_TILE_LEFT, NEO_TILE_RIGHT: +// Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick +// two, e.g. NEO_TILE_TOP + NEO_TILE_LEFT for the top-left corner. +// NEO_TILE_ROWS, NEO_TILE_COLUMNS: the matrices in the OVERALL DISPLAY +// are arranged in horizontal rows or in vertical columns, respectively; +// pick one or the other. +// NEO_TILE_PROGRESSIVE, NEO_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES +// (tiles) in the OVERALL DISPLAY proceed in the same order for every +// line, or alternate lines reverse direction; pick one. When using +// zig-zag order, the orientation of the matrices in alternate rows +// will be rotated 180 degrees (this is normal -- simplifies wiring). +// See example below for these values in action. +// Parameter 7 = pixel type flags, add together as needed: +// NEO_RGB Pixels are wired for RGB bitstream (v1 pixels) +// NEO_GRB Pixels are wired for GRB bitstream (v2 pixels) +// NEO_KHZ400 400 KHz bitstream (e.g. FLORA v1 pixels) +// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) + +Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(16, 8, PIN, + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, + NEO_GRB + NEO_KHZ800); + +const uint16_t colors[] = { + matrix->Color(255, 0, 0), matrix->Color(0, 255, 0), matrix->Color(0, 0, 255) }; + +// This could also be defined as matrix->color(255,0,0) but those defines +// are meant to work for adafruit_gfx backends that are lacking color() +#define LED_RED_VERYLOW (3 << 11) +#define LED_RED_LOW (7 << 11) +#define LED_RED_MEDIUM (15 << 11) +#define LED_RED_HIGH (31 << 11) + +#define LED_GREEN_VERYLOW (1 << 5) +#define LED_GREEN_LOW (15 << 5) +#define LED_GREEN_MEDIUM (31 << 5) +#define LED_GREEN_HIGH (63 << 5) + +#define LED_BLUE_VERYLOW 3 +#define LED_BLUE_LOW 7 +#define LED_BLUE_MEDIUM 15 +#define LED_BLUE_HIGH 31 + +#define LED_ORANGE_VERYLOW (LED_RED_VERYLOW + LED_GREEN_VERYLOW) +#define LED_ORANGE_LOW (LED_RED_LOW + LED_GREEN_LOW) +#define LED_ORANGE_MEDIUM (LED_RED_MEDIUM + LED_GREEN_MEDIUM) +#define LED_ORANGE_HIGH (LED_RED_HIGH + LED_GREEN_HIGH) + +#define LED_PURPLE_VERYLOW (LED_RED_VERYLOW + LED_BLUE_VERYLOW) +#define LED_PURPLE_LOW (LED_RED_LOW + LED_BLUE_LOW) +#define LED_PURPLE_MEDIUM (LED_RED_MEDIUM + LED_BLUE_MEDIUM) +#define LED_PURPLE_HIGH (LED_RED_HIGH + LED_BLUE_HIGH) + +#define LED_CYAN_VERYLOW (LED_GREEN_VERYLOW + LED_BLUE_VERYLOW) +#define LED_CYAN_LOW (LED_GREEN_LOW + LED_BLUE_LOW) +#define LED_CYAN_MEDIUM (LED_GREEN_MEDIUM + LED_BLUE_MEDIUM) +#define LED_CYAN_HIGH (LED_GREEN_HIGH + LED_BLUE_HIGH) + +#define LED_WHITE_VERYLOW (LED_RED_VERYLOW + LED_GREEN_VERYLOW + LED_BLUE_VERYLOW) +#define LED_WHITE_LOW (LED_RED_LOW + LED_GREEN_LOW + LED_BLUE_LOW) +#define LED_WHITE_MEDIUM (LED_RED_MEDIUM + LED_GREEN_MEDIUM + LED_BLUE_MEDIUM) +#define LED_WHITE_HIGH (LED_RED_HIGH + LED_GREEN_HIGH + LED_BLUE_HIGH) + +typedef enum { + FOUR_WHITE = 0, + BITMAP = 1, + RGB_BITMAP = 2, + LINES = 3, + BOXES = 4, + CIRCLES = 5, + GREENSCROLLTEXT = 6, + ORANGESCROLLTEXT = 7, +} MatrixDisplay; + +static const uint8_t PROGMEM + mono_bmp[][8] = + { + + { B00111100, + B01000010, + B10100101, + B10000001, + B10100101, + B10011001, + B01000010, + B00111100 }, + + { B00111100, + B01000010, + B10100101, + B10000001, + B10111101, + B10000001, + B01000010, + B00111100 }, + + { B00111100, + B01000010, + B10100101, + B10000001, + B10011001, + B10100101, + B01000010, + B00111100 }, + + { + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + }, + + { + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + }, + }; + +static const uint16_t PROGMEM + // These bitmaps were written for a backend that only supported + // 4 bits per color with Blue/Green/Red ordering while neomatrix + // uses native 565 color mapping as RGB. + // I'm leaving the arrays as is because it's easier to read + // which color is what when separated on a 4bit boundary + // The demo code will modify the arrays at runtime to be compatible + // with the neomatrix color ordering and bit depth. + RGB_bmp[][64] = { + // 00: blue, blue/red, red, red/green, green, green/blue, blue, white + { 0x100, 0x200, 0x300, 0x400, 0x600, 0x800, 0xA00, 0xF00, + 0x101, 0x202, 0x303, 0x404, 0x606, 0x808, 0xA0A, 0xF0F, + 0x001, 0x002, 0x003, 0x004, 0x006, 0x008, 0x00A, 0x00F, + 0x011, 0x022, 0x033, 0x044, 0x066, 0x088, 0x0AA, 0x0FF, + 0x010, 0x020, 0x030, 0x040, 0x060, 0x080, 0x0A0, 0x0F0, + 0x110, 0x220, 0x330, 0x440, 0x660, 0x880, 0xAA0, 0xFF0, + 0x100, 0x200, 0x300, 0x400, 0x600, 0x800, 0xA00, 0xF00, + 0x111, 0x222, 0x333, 0x444, 0x666, 0x888, 0xAAA, 0xFFF, }, + + // 01: grey to white + { 0x111, 0x222, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, + 0x222, 0x222, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, + 0x333, 0x333, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, + 0x555, 0x555, 0x555, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, + 0x777, 0x777, 0x777, 0x777, 0x777, 0x999, 0xAAA, 0xFFF, + 0x999, 0x999, 0x999, 0x999, 0x999, 0x999, 0xAAA, 0xFFF, + 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xFFF, + 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, }, + + // 02: low red to high red + { 0x001, 0x002, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F, + 0x002, 0x002, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F, + 0x003, 0x003, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F, + 0x005, 0x005, 0x005, 0x005, 0x007, 0x009, 0x00A, 0x00F, + 0x007, 0x007, 0x007, 0x007, 0x007, 0x009, 0x00A, 0x00F, + 0x009, 0x009, 0x009, 0x009, 0x009, 0x009, 0x00A, 0x00F, + 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00F, + 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, }, + + // 03: low green to high green + { 0x010, 0x020, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, + 0x020, 0x020, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, + 0x030, 0x030, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, + 0x050, 0x050, 0x050, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, + 0x070, 0x070, 0x070, 0x070, 0x070, 0x090, 0x0A0, 0x0F0, + 0x090, 0x090, 0x090, 0x090, 0x090, 0x090, 0x0A0, 0x0F0, + 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0F0, + 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, }, + + // 04: low blue to high blue + { 0x100, 0x200, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00, + 0x200, 0x200, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00, + 0x300, 0x300, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00, + 0x500, 0x500, 0x500, 0x500, 0x700, 0x900, 0xA00, 0xF00, + 0x700, 0x700, 0x700, 0x700, 0x700, 0x900, 0xA00, 0xF00, + 0x900, 0x900, 0x900, 0x900, 0x900, 0x900, 0xA00, 0xF00, + 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xF00, + 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, }, + + // 05: 1 black, 2R, 2O, 2G, 1B with 4 blue lines rising right + { 0x000, 0x200, 0x000, 0x400, 0x000, 0x800, 0x000, 0xF00, + 0x000, 0x201, 0x002, 0x403, 0x004, 0x805, 0x006, 0xF07, + 0x008, 0x209, 0x00A, 0x40B, 0x00C, 0x80D, 0x00E, 0xF0F, + 0x000, 0x211, 0x022, 0x433, 0x044, 0x855, 0x066, 0xF77, + 0x088, 0x299, 0x0AA, 0x4BB, 0x0CC, 0x8DD, 0x0EE, 0xFFF, + 0x000, 0x210, 0x020, 0x430, 0x040, 0x850, 0x060, 0xF70, + 0x080, 0x290, 0x0A0, 0x4B0, 0x0C0, 0x8D0, 0x0E0, 0xFF0, + 0x000, 0x200, 0x000, 0x500, 0x000, 0x800, 0x000, 0xF00, }, + + // 06: 4 lines of increasing red and then green + { 0x000, 0x000, 0x001, 0x001, 0x002, 0x002, 0x003, 0x003, + 0x004, 0x004, 0x005, 0x005, 0x006, 0x006, 0x007, 0x007, + 0x008, 0x008, 0x009, 0x009, 0x00A, 0x00A, 0x00B, 0x00B, + 0x00C, 0x00C, 0x00D, 0x00D, 0x00E, 0x00E, 0x00F, 0x00F, + 0x000, 0x000, 0x010, 0x010, 0x020, 0x020, 0x030, 0x030, + 0x040, 0x040, 0x050, 0x050, 0x060, 0x060, 0x070, 0x070, + 0x080, 0x080, 0x090, 0x090, 0x0A0, 0x0A0, 0x0B0, 0x0B0, + 0x0C0, 0x0C0, 0x0D0, 0x0D0, 0x0E0, 0x0E0, 0x0F0, 0x0F0, }, + + // 07: 4 lines of increasing red and then blue + { 0x000, 0x000, 0x001, 0x001, 0x002, 0x002, 0x003, 0x003, + 0x004, 0x004, 0x005, 0x005, 0x006, 0x006, 0x007, 0x007, + 0x008, 0x008, 0x009, 0x009, 0x00A, 0x00A, 0x00B, 0x00B, + 0x00C, 0x00C, 0x00D, 0x00D, 0x00E, 0x00E, 0x00F, 0x00F, + 0x000, 0x000, 0x100, 0x100, 0x200, 0x200, 0x300, 0x300, + 0x400, 0x400, 0x500, 0x500, 0x600, 0x600, 0x700, 0x700, + 0x800, 0x800, 0x900, 0x900, 0xA00, 0xA00, 0xB00, 0xB00, + 0xC00, 0xC00, 0xD00, 0xD00, 0xE00, 0xE00, 0xF00, 0xF00, }, + + // 08: criss cross of green and red with diagonal blue. + { 0xF00, 0x001, 0x003, 0x005, 0x007, 0x00A, 0x00F, 0x000, + 0x020, 0xF21, 0x023, 0x025, 0x027, 0x02A, 0x02F, 0x020, + 0x040, 0x041, 0xF43, 0x045, 0x047, 0x04A, 0x04F, 0x040, + 0x060, 0x061, 0x063, 0xF65, 0x067, 0x06A, 0x06F, 0x060, + 0x080, 0x081, 0x083, 0x085, 0xF87, 0x08A, 0x08F, 0x080, + 0x0A0, 0x0A1, 0x0A3, 0x0A5, 0x0A7, 0xFAA, 0x0AF, 0x0A0, + 0x0F0, 0x0F1, 0x0F3, 0x0F5, 0x0F7, 0x0FA, 0xFFF, 0x0F0, + 0x000, 0x001, 0x003, 0x005, 0x007, 0x00A, 0x00F, 0xF00, }, + + // 09: 2 lines of green, 2 red, 2 orange, 2 green + { 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, + 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, + 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, + 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, + 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, + 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, + 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, + 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, }, + + // 10: multicolor smiley face + { 0x000, 0x000, 0x00F, 0x00F, 0x00F, 0x00F, 0x000, 0x000, + 0x000, 0x00F, 0x000, 0x000, 0x000, 0x000, 0x00F, 0x000, + 0x00F, 0x000, 0xF00, 0x000, 0x000, 0xF00, 0x000, 0x00F, + 0x00F, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x00F, + 0x00F, 0x000, 0x0F0, 0x000, 0x000, 0x0F0, 0x000, 0x00F, + 0x00F, 0x000, 0x000, 0x0F4, 0x0F3, 0x000, 0x000, 0x00F, + 0x000, 0x00F, 0x000, 0x000, 0x000, 0x000, 0x00F, 0x000, + 0x000, 0x000, 0x00F, 0x00F, 0x00F, 0x00F, 0x000, 0x000, }, +}; + + +void setup() { + Serial.begin(115200); + matrix->begin(); + matrix->setTextWrap(false); + matrix->setBrightness(255); + matrix->setTextColor(colors[0]); + matrix->fillScreen(LED_ORANGE_HIGH); + matrix->show(); + delay(1000); +} + +int x = matrix->width(); +int pass = 0; + +#if 0 +void loop() { + matrix->fillScreen(0); + matrix->setCursor(x, 0); + matrix->print(F("Howdy")); + if(--x < -36) { + x = matrix->width(); + if(++pass >= 3) pass = 0; + matrix->setTextColor(colors[pass]); + } + matrix->show(); + delay(50); +} +#endif + + + +void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) { + uint16_t RGB_bmp_fixed[w * h]; + for (uint16_t pixel=0; pixel> 8; + g = (color & 0x0F0) >> 4; + r = color & 0x00F; + //Serial.print(" "); + //Serial.print(b); + //Serial.print("/"); + //Serial.print(g); + //Serial.print("/"); + //Serial.print(r); + //Serial.print(" -> "); + // expand from 4/4/4 bits per color to 5/6/5 + b = map(b, 0, 15, 0, 31); + g = map(g, 0, 15, 0, 63); + r = map(r, 0, 15, 0, 31); + //Serial.print(r); + //Serial.print("/"); + //Serial.print(g); + //Serial.print("/"); + //Serial.print(b); + RGB_bmp_fixed[pixel] = (r << 11) + (g << 5) + b; + //Serial.print(" -> "); + //Serial.println(RGB_bmp_fixed[pixel], HEX); + } + // Non color fixed, progmem read. + //matrix->drawRGBBitmap(x, y, bitmap, w, h, true); + // Color fixed, direct read from RAM. + matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h, false); +} + +void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { + matrix->clear(); + + switch (choice) { + + case FOUR_WHITE: + matrix->fillRect(0,0, 8,8, LED_WHITE_HIGH); + matrix->drawRect(1,1, 6,6, LED_WHITE_MEDIUM); + matrix->drawRect(2,2, 4,4, LED_WHITE_LOW); + matrix->drawRect(3,3, 2,2, LED_WHITE_VERYLOW); + break; + + case BITMAP: + matrix->drawBitmap(0, 0, mono_bmp[bmp_num], 8, 8, color); + break; + + case RGB_BITMAP: + fixdrawRGBBitmap(0, 0, RGB_bmp[bmp_num], 8, 8); + break; + + case LINES: + // Without a matrix like above, a red/green crossing isn't as good. + matrix->drawLine(0,2, 7,2, LED_RED_VERYLOW); + matrix->drawLine(0,3, 7,3, LED_RED_LOW); + matrix->drawLine(0,4, 7,4, LED_RED_MEDIUM); + matrix->drawLine(0,5, 7,5, LED_RED_HIGH); + matrix->drawLine(2,0, 2,7, LED_GREEN_VERYLOW); + matrix->drawLine(3,0, 3,7, LED_GREEN_LOW); + matrix->drawLine(4,0, 4,7, LED_GREEN_MEDIUM); + matrix->drawLine(5,0, 5,7, LED_GREEN_HIGH); + matrix->drawLine(0,0, 7,7, LED_BLUE_HIGH); + break; + + case BOXES: + matrix->drawRect(0,0, 8,8, LED_BLUE_HIGH); + matrix->drawRect(1,1, 6,6, LED_GREEN_MEDIUM); + matrix->fillRect(2,2, 4,4, LED_RED_HIGH); + break; + + case CIRCLES: + matrix->drawCircle(2,2, 2, LED_RED_MEDIUM); + matrix->drawCircle(5,5, 2, LED_BLUE_HIGH); + matrix->drawCircle(1,6, 1, LED_GREEN_LOW); + matrix->drawCircle(6,1, 1, LED_GREEN_HIGH); + break; + + case GREENSCROLLTEXT: + matrix->setTextWrap(false); // we don't wrap text so it scrolls nicely + matrix->setTextSize(1); + matrix->setTextColor(LED_GREEN_HIGH); + matrix->setRotation(3); + for (int8_t x=7; x>=-36; x--) { + matrix->clear(); + matrix->setCursor(x,0); + matrix->print("Hello"); + matrix->show(); + delay(50); + } + break; + + case ORANGESCROLLTEXT: + matrix->setRotation(0); + matrix->setTextColor(LED_ORANGE_HIGH); + for (int8_t x=7; x>=-36; x--) { + matrix->clear(); + matrix->setCursor(x,0); + matrix->print("World"); + matrix->show(); + delay(50); + } + break; + + } + matrix->show(); +} + +void loop() { + uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH }; + uint16_t scandelay[] = { 5, 50, 200, 1000 }; + + fixdrawRGBBitmap(0, 0, RGB_bmp[0], 8, 8); + delay(1000); + + // Cycle through red, green, blue, display 2 checkered patterns + for (uint8_t i=0; i<3; i++) + { + display_matrix(BITMAP, 3, bmpcolor[i]); + delay(500); + display_matrix(BITMAP, 4, bmpcolor[i]); + delay(500); + } + + for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) + { + display_matrix(RGB_BITMAP, i); + delay(3000); + } + + display_matrix(FOUR_WHITE, 0); + delay(3000); + + for (uint8_t i=0; i<=2; i++) + { + display_matrix(BITMAP, i, bmpcolor[i]); + delay(3000); + } + + display_matrix(LINES); + delay(3000); + + display_matrix(BOXES); + delay(3000); + + + display_matrix(GREENSCROLLTEXT); + + display_matrix(ORANGESCROLLTEXT); +} From 5735cdfd71e2fd5ac86f35e69f5f3319f5131095 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Thu, 6 Apr 2017 12:46:43 -0700 Subject: [PATCH 02/15] Improved demos to work on displays wider than 8x8 and center. removed old dead code from tiletest. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 95 +++++++++++------------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 01726f9..8077423 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -49,8 +49,8 @@ Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(16, 8, PIN, NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800); -const uint16_t colors[] = { - matrix->Color(255, 0, 0), matrix->Color(0, 255, 0), matrix->Color(0, 0, 255) }; +uint16_t mw = matrix->width(); +uint16_t mh = matrix->height(); // This could also be defined as matrix->color(255,0,0) but those defines // are meant to work for adafruit_gfx backends that are lacking color() @@ -280,31 +280,11 @@ void setup() { matrix->begin(); matrix->setTextWrap(false); matrix->setBrightness(255); - matrix->setTextColor(colors[0]); matrix->fillScreen(LED_ORANGE_HIGH); matrix->show(); delay(1000); } -int x = matrix->width(); -int pass = 0; - -#if 0 -void loop() { - matrix->fillScreen(0); - matrix->setCursor(x, 0); - matrix->print(F("Howdy")); - if(--x < -36) { - x = matrix->width(); - if(++pass >= 3) pass = 0; - matrix->setTextColor(colors[pass]); - } - matrix->show(); - delay(50); -} -#endif - - void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) { uint16_t RGB_bmp_fixed[w * h]; @@ -342,60 +322,68 @@ void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, i matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h, false); } -void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { - matrix->clear(); +void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { + static uint16_t bmx,bmy; switch (choice) { case FOUR_WHITE: - matrix->fillRect(0,0, 8,8, LED_WHITE_HIGH); - matrix->drawRect(1,1, 6,6, LED_WHITE_MEDIUM); - matrix->drawRect(2,2, 4,4, LED_WHITE_LOW); - matrix->drawRect(3,3, 2,2, LED_WHITE_VERYLOW); + matrix->clear(); + matrix->fillRect(0,0, mw,mh, LED_WHITE_HIGH); + matrix->drawRect(1,1, mw-2,mh-2, LED_WHITE_MEDIUM); + matrix->drawRect(2,2, mw-4,mh-4, LED_WHITE_LOW); + matrix->drawRect(3,3, mw-6,mh-6, LED_WHITE_VERYLOW); break; case BITMAP: - matrix->drawBitmap(0, 0, mono_bmp[bmp_num], 8, 8, color); + matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); + bmx = (bmx + 8) % mw; + bmy = (bmy + 8) % mh; break; case RGB_BITMAP: - fixdrawRGBBitmap(0, 0, RGB_bmp[bmp_num], 8, 8); + fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8); + bmx = (bmx + 8) % mw; + bmy = (bmy + 8) % mh; break; case LINES: - // Without a matrix like above, a red/green crossing isn't as good. - matrix->drawLine(0,2, 7,2, LED_RED_VERYLOW); - matrix->drawLine(0,3, 7,3, LED_RED_LOW); - matrix->drawLine(0,4, 7,4, LED_RED_MEDIUM); - matrix->drawLine(0,5, 7,5, LED_RED_HIGH); - matrix->drawLine(2,0, 2,7, LED_GREEN_VERYLOW); - matrix->drawLine(3,0, 3,7, LED_GREEN_LOW); - matrix->drawLine(4,0, 4,7, LED_GREEN_MEDIUM); - matrix->drawLine(5,0, 5,7, LED_GREEN_HIGH); - matrix->drawLine(0,0, 7,7, LED_BLUE_HIGH); + matrix->clear(); + matrix->drawLine(0,2, mw-1,2, LED_RED_VERYLOW); + matrix->drawLine(0,3, mw-1,3, LED_RED_LOW); + matrix->drawLine(0,4, mw-1,4, LED_RED_MEDIUM); + matrix->drawLine(0,5, mw-1,5, LED_RED_HIGH); + matrix->drawLine(2,0, 2,mh-1, LED_GREEN_VERYLOW); + matrix->drawLine(3,0, 3,mh-1, LED_GREEN_LOW); + matrix->drawLine(4,0, 4,mh-1, LED_GREEN_MEDIUM); + matrix->drawLine(5,0, 5,mh-1, LED_GREEN_HIGH); + matrix->drawLine(0,0, mh-1,mh-1, LED_BLUE_HIGH); break; case BOXES: - matrix->drawRect(0,0, 8,8, LED_BLUE_HIGH); - matrix->drawRect(1,1, 6,6, LED_GREEN_MEDIUM); - matrix->fillRect(2,2, 4,4, LED_RED_HIGH); + matrix->clear(); + matrix->drawRect(0,0, mw,mh, LED_BLUE_HIGH); + matrix->drawRect(1,1, mw-2,mh-2, LED_GREEN_MEDIUM); + matrix->fillRect(2,2, mw-4,mh-4, LED_RED_HIGH); break; case CIRCLES: - matrix->drawCircle(2,2, 2, LED_RED_MEDIUM); - matrix->drawCircle(5,5, 2, LED_BLUE_HIGH); - matrix->drawCircle(1,6, 1, LED_GREEN_LOW); - matrix->drawCircle(6,1, 1, LED_GREEN_HIGH); + matrix->clear(); + matrix->drawCircle(mw/2,mh/2, 2, LED_RED_MEDIUM); + matrix->drawCircle(mw/2-3,mh/2-3, 2, LED_BLUE_HIGH); + matrix->drawCircle(1,mh-2, 1, LED_GREEN_LOW); + matrix->drawCircle(mw-2,1, 1, LED_GREEN_HIGH); break; case GREENSCROLLTEXT: + matrix->clear(); matrix->setTextWrap(false); // we don't wrap text so it scrolls nicely matrix->setTextSize(1); matrix->setTextColor(LED_GREEN_HIGH); matrix->setRotation(3); for (int8_t x=7; x>=-36; x--) { matrix->clear(); - matrix->setCursor(x,0); + matrix->setCursor(x,mw/2-4); matrix->print("Hello"); matrix->show(); delay(50); @@ -403,11 +391,12 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { break; case ORANGESCROLLTEXT: + matrix->clear(); matrix->setRotation(0); matrix->setTextColor(LED_ORANGE_HIGH); for (int8_t x=7; x>=-36; x--) { matrix->clear(); - matrix->setCursor(x,0); + matrix->setCursor(x,mh/2-4); matrix->print("World"); matrix->show(); delay(50); @@ -422,9 +411,12 @@ void loop() { uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH }; uint16_t scandelay[] = { 5, 50, 200, 1000 }; - fixdrawRGBBitmap(0, 0, RGB_bmp[0], 8, 8); + matrix->clear(); + fixdrawRGBBitmap(mw/2-4, mh/2-4, RGB_bmp[10], 8, 8); + matrix->show(); delay(1000); + matrix->clear(); // Cycle through red, green, blue, display 2 checkered patterns for (uint8_t i=0; i<3; i++) { @@ -437,12 +429,13 @@ void loop() { for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) { display_matrix(RGB_BITMAP, i); - delay(3000); + delay(1500); } display_matrix(FOUR_WHITE, 0); delay(3000); + matrix->clear(); for (uint8_t i=0; i<=2; i++) { display_matrix(BITMAP, i, bmpcolor[i]); From 9b5cf1d90f4bb77ee710b80df4ae546e14e18b27 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Thu, 6 Apr 2017 12:51:04 -0700 Subject: [PATCH 03/15] small display improvements. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 8077423..0038434 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -351,8 +351,8 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { matrix->clear(); matrix->drawLine(0,2, mw-1,2, LED_RED_VERYLOW); matrix->drawLine(0,3, mw-1,3, LED_RED_LOW); - matrix->drawLine(0,4, mw-1,4, LED_RED_MEDIUM); - matrix->drawLine(0,5, mw-1,5, LED_RED_HIGH); + matrix->drawLine(0,mw/2, mw-1,mw/2, LED_RED_MEDIUM); + matrix->drawLine(0,mw/2+1, mw-1,mw/2+1, LED_RED_HIGH); matrix->drawLine(2,0, 2,mh-1, LED_GREEN_VERYLOW); matrix->drawLine(3,0, 3,mh-1, LED_GREEN_LOW); matrix->drawLine(4,0, 4,mh-1, LED_GREEN_MEDIUM); @@ -438,8 +438,10 @@ void loop() { matrix->clear(); for (uint8_t i=0; i<=2; i++) { + if (i==2) matrix->clear(); display_matrix(BITMAP, i, bmpcolor[i]); delay(3000); + // prevent 3rd bitmap from being overlayed on top of 1st } display_matrix(LINES); From 78dbe0e986b9c2ead82043b48d79c466bd2ff032 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Thu, 6 Apr 2017 17:29:19 -0700 Subject: [PATCH 04/15] Improvements to demos, and support for screens bigger than 16x8. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 74 +++++++++++++++--------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 0038434..a602464 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -286,6 +286,7 @@ void setup() { } +// Convert a BGR 4/4/4 bitmap to RGB 5/6/5 used by Adafruit_GFX void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) { uint16_t RGB_bmp_fixed[w * h]; for (uint16_t pixel=0; pixeldrawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); bmx = (bmx + 8) % mw; - bmy = (bmy + 8) % mh; + if (!bmx) bmy = (bmy + 8) % mh; break; case RGB_BITMAP: fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8); bmx = (bmx + 8) % mw; - bmy = (bmy + 8) % mh; + if (!bmx) bmy = (bmy + 8) % mh; break; case LINES: matrix->clear(); + + // 4 levels of crossing red lines. matrix->drawLine(0,2, mw-1,2, LED_RED_VERYLOW); matrix->drawLine(0,3, mw-1,3, LED_RED_LOW); - matrix->drawLine(0,mw/2, mw-1,mw/2, LED_RED_MEDIUM); - matrix->drawLine(0,mw/2+1, mw-1,mw/2+1, LED_RED_HIGH); - matrix->drawLine(2,0, 2,mh-1, LED_GREEN_VERYLOW); - matrix->drawLine(3,0, 3,mh-1, LED_GREEN_LOW); - matrix->drawLine(4,0, 4,mh-1, LED_GREEN_MEDIUM); - matrix->drawLine(5,0, 5,mh-1, LED_GREEN_HIGH); - matrix->drawLine(0,0, mh-1,mh-1, LED_BLUE_HIGH); + matrix->drawLine(0,mh/2, mw-1,mh/2, LED_RED_MEDIUM); + matrix->drawLine(0,mh/2+1, mw-1,mh/2+1, LED_RED_HIGH); + + // 4 levels of crossing green lines. + matrix->drawLine(mw/2-2, 0, mw/2-2, mh-1, LED_GREEN_VERYLOW); + matrix->drawLine(mw/2-1, 0, mw/2-1, mh-1, LED_GREEN_LOW); + matrix->drawLine(mw/2+0, 0, mw/2+0, mh-1, LED_GREEN_MEDIUM); + matrix->drawLine(mw/2+1, 0, mw/2+1, mh-1, LED_GREEN_HIGH); + + // Diagonal blue line. + matrix->drawLine(0,0, mw-1,mh-1, LED_BLUE_HIGH); break; case BOXES: @@ -408,48 +415,59 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { } void loop() { + // clear the screen after X bitmaps have been displayed and we + // loop back to the top left corner + // 8x8 => 1, 16x8 => 2, 17x9 => 6 + static uint8_t pixmap_count = ((mw+7)/8) * ((mh+7)/8); uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH }; uint16_t scandelay[] = { 5, 50, 200, 1000 }; - matrix->clear(); - fixdrawRGBBitmap(mw/2-4, mh/2-4, RGB_bmp[10], 8, 8); - matrix->show(); - delay(1000); + Serial.print("Screen pixmap capacity: "); + Serial.println(pixmap_count); matrix->clear(); + // multicolor bitmap sent as many times as we can display an 8x8 pixel + for (uint8_t i=0; i<=pixmap_count; i++) + { + display_matrix(RGB_BITMAP, 0); + } + delay(2000); + + for (uint8_t i=0; i<=2; i++) + { + if (i % pixmap_count == 0) matrix->clear(); + display_matrix(BITMAP, i, bmpcolor[i]); + delay(1500); + } + // Cycle through red, green, blue, display 2 checkered patterns + // useful to debug some screen types and alignment. for (uint8_t i=0; i<3; i++) { + if (i % pixmap_count == 0) matrix->clear(); display_matrix(BITMAP, 3, bmpcolor[i]); delay(500); display_matrix(BITMAP, 4, bmpcolor[i]); delay(500); } + display_matrix(LINES); + delay(3000); + + display_matrix(BOXES); + delay(3000); + + for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) { display_matrix(RGB_BITMAP, i); delay(1500); } + // Fill the screen with multiple levels of white to guage the quality display_matrix(FOUR_WHITE, 0); delay(3000); - matrix->clear(); - for (uint8_t i=0; i<=2; i++) - { - if (i==2) matrix->clear(); - display_matrix(BITMAP, i, bmpcolor[i]); - delay(3000); - // prevent 3rd bitmap from being overlayed on top of 1st - } - - display_matrix(LINES); - delay(3000); - - display_matrix(BOXES); - delay(3000); - display_matrix(GREENSCROLLTEXT); From c2773c3a0605c83be65588f1378d12c2a55e317a Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Thu, 6 Apr 2017 17:44:30 -0700 Subject: [PATCH 05/15] Small demo improvemnts. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index a602464..f3d7f01 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -54,6 +54,8 @@ uint16_t mh = matrix->height(); // This could also be defined as matrix->color(255,0,0) but those defines // are meant to work for adafruit_gfx backends that are lacking color() +#define LED_BLACK 0 + #define LED_RED_VERYLOW (3 << 11) #define LED_RED_LOW (7 << 11) #define LED_RED_MEDIUM (15 << 11) @@ -283,6 +285,7 @@ void setup() { matrix->fillScreen(LED_ORANGE_HIGH); matrix->show(); delay(1000); + matrix->clear(); } @@ -337,6 +340,10 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { break; case BITMAP: + // Clear the space under the bitmap that will be drawn as + // drawing a single color pixmap does not write over pixels + // that are nul, and leaves the data that was underneath + matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK); matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); bmx = (bmx + 8) % mw; if (!bmx) bmy = (bmy + 8) % mh; @@ -425,7 +432,6 @@ void loop() { Serial.print("Screen pixmap capacity: "); Serial.println(pixmap_count); - matrix->clear(); // multicolor bitmap sent as many times as we can display an 8x8 pixel for (uint8_t i=0; i<=pixmap_count; i++) { @@ -433,24 +439,23 @@ void loop() { } delay(2000); - for (uint8_t i=0; i<=2; i++) - { - if (i % pixmap_count == 0) matrix->clear(); - display_matrix(BITMAP, i, bmpcolor[i]); - delay(1500); - } // Cycle through red, green, blue, display 2 checkered patterns // useful to debug some screen types and alignment. for (uint8_t i=0; i<3; i++) { - if (i % pixmap_count == 0) matrix->clear(); - display_matrix(BITMAP, 3, bmpcolor[i]); + display_matrix(BITMAP, 3 + (i % 2), bmpcolor[i]); delay(500); - display_matrix(BITMAP, 4, bmpcolor[i]); + display_matrix(BITMAP, 4 - (i % 2), bmpcolor[i]); delay(500); } + for (uint8_t i=0; i<=2; i++) + { + display_matrix(BITMAP, i, bmpcolor[i]); + delay(1500); + } + display_matrix(LINES); delay(3000); From 7b2d83c10fb415116f4bee4c15a4748e97ee6661 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Wed, 19 Apr 2017 08:35:58 -0700 Subject: [PATCH 06/15] Tweaked demos for a 24x24 matrix. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 55 +++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index f3d7f01..c8b2b13 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -1,5 +1,6 @@ // Adafruit_NeoMatrix example for single NeoPixel Shield. // By Marc MERLIN +// Contains code (c) Adafruit, license BSD #include #include @@ -44,7 +45,7 @@ // NEO_KHZ400 400 KHz bitstream (e.g. FLORA v1 pixels) // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) -Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(16, 8, PIN, +Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(24, 24, PIN, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800); @@ -98,8 +99,7 @@ typedef enum { LINES = 3, BOXES = 4, CIRCLES = 5, - GREENSCROLLTEXT = 6, - ORANGESCROLLTEXT = 7, + SCROLLTEXT = 6, } MatrixDisplay; static const uint8_t PROGMEM @@ -359,8 +359,8 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { matrix->clear(); // 4 levels of crossing red lines. - matrix->drawLine(0,2, mw-1,2, LED_RED_VERYLOW); - matrix->drawLine(0,3, mw-1,3, LED_RED_LOW); + matrix->drawLine(0,mh/2-2, mw-1,2, LED_RED_VERYLOW); + matrix->drawLine(0,mh/2-1, mw-1,3, LED_RED_LOW); matrix->drawLine(0,mh/2, mw-1,mh/2, LED_RED_MEDIUM); matrix->drawLine(0,mh/2+1, mw-1,mh/2+1, LED_RED_HIGH); @@ -372,6 +372,7 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { // Diagonal blue line. matrix->drawLine(0,0, mw-1,mh-1, LED_BLUE_HIGH); + matrix->drawLine(0,mh-1, mw-1,0, LED_ORANGE_MEDIUM); break; case BOXES: @@ -379,6 +380,7 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { matrix->drawRect(0,0, mw,mh, LED_BLUE_HIGH); matrix->drawRect(1,1, mw-2,mh-2, LED_GREEN_MEDIUM); matrix->fillRect(2,2, mw-4,mh-4, LED_RED_HIGH); + matrix->fillRect(3,3, mw-6,mh-6, LED_ORANGE_MEDIUM); break; case CIRCLES: @@ -389,29 +391,31 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { matrix->drawCircle(mw-2,1, 1, LED_GREEN_HIGH); break; - case GREENSCROLLTEXT: + case SCROLLTEXT: matrix->clear(); matrix->setTextWrap(false); // we don't wrap text so it scrolls nicely matrix->setTextSize(1); - matrix->setTextColor(LED_GREEN_HIGH); - matrix->setRotation(3); - for (int8_t x=7; x>=-36; x--) { + matrix->setRotation(0); + for (int8_t x=7; x>=-42; x--) { matrix->clear(); - matrix->setCursor(x,mw/2-4); + matrix->setCursor(x,0); + matrix->setTextColor(LED_GREEN_HIGH); matrix->print("Hello"); + if (mh>8) { + matrix->setCursor(-20-x,mh-8); + matrix->setTextColor(LED_ORANGE_HIGH); + matrix->print("World"); + } matrix->show(); delay(50); } - break; - - case ORANGESCROLLTEXT: - matrix->clear(); - matrix->setRotation(0); - matrix->setTextColor(LED_ORANGE_HIGH); - for (int8_t x=7; x>=-36; x--) { + + matrix->setRotation(3); + matrix->setTextColor(LED_BLUE_HIGH); + for (int8_t x=7; x>=-60; x--) { matrix->clear(); matrix->setCursor(x,mh/2-4); - matrix->print("World"); + matrix->print("Sideways Too!"); matrix->show(); delay(50); } @@ -432,7 +436,7 @@ void loop() { Serial.print("Screen pixmap capacity: "); Serial.println(pixmap_count); - // multicolor bitmap sent as many times as we can display an 8x8 pixel + // multicolor bitmap sent as many times as we can display an 8x8 pixmap for (uint8_t i=0; i<=pixmap_count; i++) { display_matrix(RGB_BITMAP, 0); @@ -453,8 +457,10 @@ void loop() { for (uint8_t i=0; i<=2; i++) { display_matrix(BITMAP, i, bmpcolor[i]); - delay(1500); + delay(mw>8?500:1500); } + // If we have multiple pixmaps displayed at once, wait a bit longer. + delay(mw>8?1500:500); display_matrix(LINES); delay(3000); @@ -466,15 +472,14 @@ void loop() { for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) { display_matrix(RGB_BITMAP, i); - delay(1500); + delay(mw>8?500:1500); } // Fill the screen with multiple levels of white to guage the quality display_matrix(FOUR_WHITE, 0); delay(3000); - - display_matrix(GREENSCROLLTEXT); - - display_matrix(ORANGESCROLLTEXT); + display_matrix(SCROLLTEXT); } + +// vim:sts=4:sw=4 From b84140a9e182bbe76b11f160671a7a0b08948f72 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Wed, 19 Apr 2017 08:39:06 -0700 Subject: [PATCH 07/15] Reset rotation and cursor location after text scroll. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index c8b2b13..3d8ac31 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -419,6 +419,8 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { matrix->show(); delay(50); } + matrix->setRotation(0); + matrix->setCursor(0,0); break; } From 02763c759cf6aa4a70ff5aa2dc039ba186be322b Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sat, 22 Apr 2017 21:39:02 -0700 Subject: [PATCH 08/15] fixes and new scroll panning demo. - Added 3 24x24 bitmaps that can be used for scrolling on smaller displays. - fixed RGB_BITMAP to display in the right place on displays not multiple of 8x8 - changed brightness to 32 so that it's less blinding and to allow a 12x12 neopixel matrix to run off 500mA from USB. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 88 +++++++++++++++++++----- examples/MatrixGFXDemo/bluesmiley24.h | 46 +++++++++++++ examples/MatrixGFXDemo/heart24.h | 53 ++++++++++++++ examples/MatrixGFXDemo/yellowsmiley24.h | 46 +++++++++++++ 4 files changed, 214 insertions(+), 19 deletions(-) create mode 100644 examples/MatrixGFXDemo/bluesmiley24.h create mode 100644 examples/MatrixGFXDemo/heart24.h create mode 100644 examples/MatrixGFXDemo/yellowsmiley24.h diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 3d8ac31..0242a65 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -5,12 +5,26 @@ #include #include #include +//#include "heart24.h" +#include "yellowsmiley24.h" +//#include "bluesmiley24.h" #ifndef PSTR #define PSTR // Make Arduino Due happy #endif #define PIN 6 +typedef enum { + FOUR_WHITE = 0, + BITMAP = 1, + RGB_BITMAP = 2, + LINES = 3, + BOXES = 4, + CIRCLES = 5, + SCROLLTEXT = 6, + BOUNCE_BITMAP = 7, +} MatrixDisplay; + // MATRIX DECLARATION: // Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display) // Parameter 2 = height of each matrix @@ -92,16 +106,6 @@ uint16_t mh = matrix->height(); #define LED_WHITE_MEDIUM (LED_RED_MEDIUM + LED_GREEN_MEDIUM + LED_BLUE_MEDIUM) #define LED_WHITE_HIGH (LED_RED_HIGH + LED_GREEN_HIGH + LED_BLUE_HIGH) -typedef enum { - FOUR_WHITE = 0, - BITMAP = 1, - RGB_BITMAP = 2, - LINES = 3, - BOXES = 4, - CIRCLES = 5, - SCROLLTEXT = 6, -} MatrixDisplay; - static const uint8_t PROGMEM mono_bmp[][8] = { @@ -281,7 +285,8 @@ void setup() { Serial.begin(115200); matrix->begin(); matrix->setTextWrap(false); - matrix->setBrightness(255); + //matrix->setBrightness(255); + matrix->setBrightness(32); matrix->fillScreen(LED_ORANGE_HIGH); matrix->show(); delay(1000); @@ -345,14 +350,18 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { // that are nul, and leaves the data that was underneath matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK); matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); - bmx = (bmx + 8) % mw; - if (!bmx) bmy = (bmy + 8) % mh; + bmx += 8; + if (bmx > mw) bmx = 0; + if (!bmx) bmy += 8; + if (bmy > mh) bmy = 0; break; case RGB_BITMAP: fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8); - bmx = (bmx + 8) % mw; - if (!bmx) bmy = (bmy + 8) % mh; + bmx += 8; + if (bmx > mw) bmx = 0; + if (!bmx) bmy += 8; + if (bmy > mh) bmy = 0; break; case LINES: @@ -401,8 +410,8 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { matrix->setCursor(x,0); matrix->setTextColor(LED_GREEN_HIGH); matrix->print("Hello"); - if (mh>8) { - matrix->setCursor(-20-x,mh-8); + if (mh>11) { + matrix->setCursor(-20-x,min(9, mh-7)); matrix->setTextColor(LED_ORANGE_HIGH); matrix->print("World"); } @@ -423,6 +432,44 @@ void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { matrix->setCursor(0,0); break; + case BOUNCE_BITMAP: + { + // keep integer math, deal with values 16 times too big + int16_t xf = (mw/2-4) << 4; + int16_t yf = (mh/2-4) << 4; + int16_t xfc = random(16); + int16_t yfc = random(16); + int16_t xfdir = 1; + int16_t yfdir = 1; + + for (uint8_t i=1; i<255; i++) { + bool updDir = false; + + // and then dvide by 16 here. + int16_t x = xf >> 4; + int16_t y = yf >> 4; + + matrix->clear(); + matrix->drawRGBBitmap(x, y, heart, 24, 24, true); + matrix->show(); + + xf += xfc*xfdir; + yf += yfc*yfdir; + // Deal with bouncing off the 'walls' + if (xf >= (mw-8) << 4) { xfdir *= -1; updDir = true ; }; + if (xf <= (mw-24 << 4)) { xfdir *= -1; updDir = true ; }; + if (yf >= (mh-8) << 4) { yfdir *= -1; updDir = true ; }; + if (yf <= (mh-24 << 4)) { yfdir *= -1; updDir = true ; }; + if (updDir) { + // Add -1, 0 or 1 but bind result to 1 to 1. + xfc = constrain(xfc + random(-1, 2), 1, 16); + yfc = constrain(xfc + random(-1, 2), 1, 16); + } + delay(20); + } + } + break; + } matrix->show(); } @@ -437,14 +484,13 @@ void loop() { Serial.print("Screen pixmap capacity: "); Serial.println(pixmap_count); + display_matrix(RGB_BITMAP, 0); // multicolor bitmap sent as many times as we can display an 8x8 pixmap for (uint8_t i=0; i<=pixmap_count; i++) { display_matrix(RGB_BITMAP, 0); } - delay(2000); - // Cycle through red, green, blue, display 2 checkered patterns // useful to debug some screen types and alignment. @@ -482,6 +528,10 @@ void loop() { delay(3000); display_matrix(SCROLLTEXT); + delay(2000); + + display_matrix(BOUNCE_BITMAP, 0); + delay(2000); } // vim:sts=4:sw=4 diff --git a/examples/MatrixGFXDemo/bluesmiley24.h b/examples/MatrixGFXDemo/bluesmiley24.h new file mode 100644 index 0000000..71c8201 --- /dev/null +++ b/examples/MatrixGFXDemo/bluesmiley24.h @@ -0,0 +1,46 @@ +// Generated by : UTFTConverter v0.1 +// Generated from : bluesmiley24.jpg +// Time generated : 2017-04-23 04:27:05.368571 UTC +// Image Size : 24x24 pixels +// Memory usage : 1152 bytes + +#include + +const unsigned short heart[576] PROGMEM={ +0x0000, 0x0040, 0x0020, 0x0802, 0x0802, 0x0001, 0x0041, 0x0020, 0x0002, 0x1002, 0x0801, 0x0020, 0x0800, 0x0000, 0x0040, 0x0060, // 0x0010 (16) pixels +0x0800, 0x0000, 0x0001, 0x0001, 0x0800, 0x0800, 0x0000, 0x1000, 0x0020, 0x0000, 0x0000, 0x0042, 0x0020, 0x0000, 0x0801, 0x0000, // 0x0020 (32) pixels +0x0020, 0x0800, 0x0000, 0x0000, 0x2000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0021, 0x0020, 0x0000, 0x0041, 0x0001, 0x0001, 0x0001, // 0x0030 (48) pixels +0x0000, 0x0800, 0x1021, 0x0000, 0x0020, 0x0020, 0x0000, 0x0000, 0x0040, 0x0020, 0x0001, 0x0043, 0x0002, 0x0022, 0x0021, 0x1000, // 0x0040 (64) pixels +0x0801, 0x0000, 0x0000, 0x0000, 0x0021, 0x0061, 0x0000, 0x0041, 0x0801, 0x0000, 0x0000, 0x0800, 0x0000, 0x0020, 0x0000, 0x1881, // 0x0050 (80) pixels +0x18E2, 0x0189, 0x23F7, 0x1BD8, 0x03F8, 0x33D7, 0x00E9, 0x0044, 0x0001, 0x1020, 0x0000, 0x0001, 0x0000, 0x0800, 0x0000, 0x0000, // 0x0060 (96) pixels +0x0801, 0x0040, 0x0020, 0x0000, 0x0021, 0x0001, 0x0000, 0xBDB7, 0x9F5F, 0x4E3E, 0x261F, 0x0CDB, 0x047A, 0x2C7C, 0x1338, 0x02D4, // 0x0070 (112) pixels +0x0969, 0x0000, 0x0000, 0x0821, 0x0800, 0x0800, 0x0801, 0x0801, 0x0800, 0x0021, 0x0021, 0x0000, 0x0000, 0x0000, 0xCF5D, 0xA7BF, // 0x0080 (128) pixels +0x2E9E, 0x1E3E, 0x261F, 0x051B, 0x5E3F, 0x0418, 0x0337, 0x453F, 0x0233, 0x11EF, 0x0002, 0x0800, 0x0000, 0x0041, 0x0000, 0x0000, // 0x0090 (144) pixels +0x0800, 0x0001, 0x0000, 0x0800, 0x0001, 0xC6DC, 0xD7FF, 0x6F5D, 0x2EBF, 0x4E3D, 0x4D5A, 0x15BC, 0x3C7A, 0x5DFB, 0x3437, 0x02D7, // 0x00A0 (160) pixels +0x0255, 0x54FE, 0x11AD, 0x0043, 0x0001, 0x0020, 0x0000, 0x0020, 0x0800, 0x0041, 0x0020, 0x0862, 0x7D16, 0xB77F, 0xA69B, 0x969B, // 0x00B0 (176) pixels +0x53B0, 0xADB5, 0xAEDC, 0x25DD, 0x5D3C, 0xADB6, 0x836D, 0xA61C, 0x3B74, 0x12B2, 0x1B34, 0x09CC, 0x0001, 0x0000, 0x0022, 0x0001, // 0x00C0 (192) pixels +0x0800, 0x0001, 0x0020, 0x1064, 0x6DFC, 0x659A, 0xAE7B, 0xE75F, 0x18E7, 0x3206, 0x5D76, 0x159E, 0x34DC, 0x5391, 0x18E5, 0x8D58, // 0x00D0 (208) pixels +0xD7FF, 0x74FA, 0x341B, 0x0211, 0x0063, 0x0820, 0x0001, 0x0802, 0x0000, 0x0800, 0x0822, 0x3C97, 0x35BD, 0x565E, 0x763D, 0x2D18, // 0x00E0 (224) pixels +0x0D5B, 0x255A, 0x359C, 0x155B, 0x3DDF, 0x24BC, 0x1B97, 0x54D9, 0x5436, 0x7E5F, 0x0252, 0x3C3B, 0x122E, 0x0000, 0x0020, 0x0001, // 0x00F0 (240) pixels +0x0800, 0x0020, 0x0004, 0x1419, 0x24FC, 0x1457, 0x3CB9, 0x2D1A, 0x2DBC, 0x3DFD, 0x4DBD, 0x4D7B, 0x557A, 0x4D7B, 0x4CDB, 0x6CDB, // 0x0100 (256) pixels +0x3BD6, 0x2373, 0x3313, 0x0AF6, 0x0AD3, 0x0020, 0x0820, 0x0022, 0x0800, 0x0020, 0x1A6F, 0x1337, 0x3418, 0x6D5B, 0x967E, 0xBF1F, // 0x0110 (272) pixels +0xE71D, 0xEF7E, 0xE75E, 0xEFBF, 0xE77E, 0xEF9D, 0xF79E, 0xEF5E, 0xC7DF, 0xBEDF, 0x7D7A, 0x4CBB, 0x2B34, 0x0022, 0x0800, 0x0002, // 0x0120 (288) pixels +0x0000, 0x0001, 0x124F, 0x12D5, 0x4C9A, 0x9DFB, 0xD7BE, 0xE7DF, 0xFFDF, 0xFF7F, 0xFF9F, 0xEF9F, 0xEFFF, 0xEFBF, 0xF7FE, 0xEFDC, // 0x0130 (304) pixels +0xF7FE, 0xD77F, 0x7557, 0x3C17, 0x3B55, 0x0002, 0x1000, 0x0001, 0x0001, 0x1001, 0x1A4D, 0x0A74, 0x2B58, 0x6CF6, 0xE7FE, 0xEFDF, // 0x0140 (320) pixels +0xE7BE, 0xE79F, 0xE7DF, 0xE77E, 0xD79F, 0xE77E, 0xE75D, 0xEF9E, 0xEFBF, 0xD77F, 0x7434, 0x0292, 0x44DA, 0x0002, 0x0800, 0x0061, // 0x0150 (336) pixels +0x0001, 0x0000, 0x0044, 0x0A33, 0x1277, 0x3B93, 0xC6DB, 0xE6FE, 0xD6FD, 0xD77F, 0xB6FC, 0xCF1D, 0xBEFC, 0xCEBA, 0xD6FC, 0xD6DF, // 0x0160 (352) pixels +0xD79F, 0xADFA, 0x5334, 0x0B58, 0x4D7C, 0x0000, 0x0820, 0x0040, 0x0022, 0x0000, 0x0003, 0x0A11, 0x0213, 0x11EF, 0x8D16, 0xE75E, // 0x0170 (368) pixels +0xDF3F, 0xDF1F, 0xE79F, 0xEF7E, 0xDFDF, 0xE75F, 0xDF5E, 0xCF9F, 0xE73D, 0x7CB6, 0x02B3, 0x13FC, 0x8DBE, 0x0040, 0x0020, 0x0021, // 0x0180 (384) pixels +0x0043, 0x0000, 0x0801, 0x012B, 0x0234, 0x0232, 0x2A6F, 0xC6BD, 0xDFDF, 0xD75F, 0xD77F, 0xCF7F, 0xD77F, 0xDF5E, 0xD77D, 0xD7FE, // 0x0190 (400) pixels +0xCE7E, 0x2B16, 0x041C, 0x459F, 0x0025, 0x0820, 0x0040, 0x0001, 0x0000, 0x0000, 0x1000, 0x0844, 0x120F, 0x0253, 0x0253, 0x2291, // 0x01A0 (416) pixels +0xA61A, 0xD75F, 0xCF7E, 0xCFBE, 0xCF9F, 0xD75F, 0xCF5F, 0xA6DE, 0x3C99, 0x041B, 0x353F, 0x3311, 0x0020, 0x0000, 0x0001, 0x0801, // 0x01B0 (432) pixels +0x0820, 0x0000, 0x0000, 0x0800, 0x0002, 0x0A30, 0x02D7, 0x0275, 0x01B2, 0x2AB4, 0x6478, 0x6CF8, 0x6D1A, 0x5C7B, 0x33DB, 0x0338, // 0x01C0 (448) pixels +0x041C, 0x361F, 0x4C96, 0x0001, 0x0840, 0x0021, 0x0800, 0x0000, 0x0000, 0x0000, 0x0041, 0x0000, 0x1000, 0x18A5, 0x4375, 0x23DA, // 0x01D0 (464) pixels +0x035D, 0x035B, 0x035A, 0x0B7A, 0x031A, 0x033B, 0x033B, 0x24FF, 0x555F, 0x33B0, 0x08E2, 0x0821, 0x0001, 0x0820, 0x0800, 0x0020, // 0x01E0 (480) pixels +0x0021, 0x0001, 0x0801, 0x0000, 0x0000, 0x0800, 0x0042, 0x198B, 0x2418, 0x253C, 0x0CFD, 0x0C3D, 0x247F, 0x34FF, 0x5DBD, 0x43F4, // 0x01F0 (496) pixels +0x1106, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0800, 0x0000, 0x0000, 0x0021, 0x0000, 0x0800, 0x1000, // 0x0200 (512) pixels +0x0042, 0x01A7, 0x1AEE, 0x2B11, 0x2AF1, 0x22CF, 0x00C3, 0x0800, 0x0801, 0x0021, 0x0022, 0x0042, 0x0000, 0x0820, 0x0001, 0x0001, // 0x0210 (528) pixels +0x0800, 0x0000, 0x0040, 0x0000, 0x0000, 0x0022, 0x0821, 0x0800, 0x1800, 0x0800, 0x0000, 0x0800, 0x0821, 0x0000, 0x0000, 0x0800, // 0x0220 (544) pixels +0x0002, 0x0061, 0x0020, 0x0001, 0x0001, 0x0000, 0x0021, 0x0000, 0x0000, 0x0021, 0x0000, 0x0021, 0x0021, 0x0020, 0x0000, 0x0001, // 0x0230 (560) pixels +0x0020, 0x0820, 0x0001, 0x0000, 0x0020, 0x0000, 0x0800, 0x0821, 0x0020, 0x0800, 0x0800, 0x0000, 0x0000, 0x0041, 0x0020, 0x0020, // 0x0240 (576) pixels +}; diff --git a/examples/MatrixGFXDemo/heart24.h b/examples/MatrixGFXDemo/heart24.h new file mode 100644 index 0000000..ff4796c --- /dev/null +++ b/examples/MatrixGFXDemo/heart24.h @@ -0,0 +1,53 @@ +// Generated by : ImageConverter 565 Online +// Generated from : heart.png +// Time generated : Wed, 19 Apr 17 18:35:04 +0200 (Server timezone: CET) +// Image Size : 24x24 pixels +// Memory usage : 1152 bytes + + +#if defined(__AVR__) + #include +#elif defined(__PIC32MX__) + #define PROGMEM +#elif defined(__arm__) + #define PROGMEM +#endif + +const unsigned short bitmap[576] PROGMEM={ +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x9800, 0x9800, 0xA020, 0xA020, 0xA000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x9800, // 0x0040 (64) pixels +0x9800, 0x9800, 0x9820, 0x9800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x9800, 0xA020, 0xB102, 0xC245, 0xC205, 0xB902, // 0x0050 (80) pixels +0xB081, 0x9020, 0x2000, 0x0000, 0x0000, 0x0000, 0x9800, 0xA8A1, 0xB9C4, 0xC1C4, 0xB8E2, 0xB081, 0xA020, 0x5800, 0x0000, 0x0000, // 0x0060 (96) pixels +0x0000, 0x0000, 0xA020, 0xB9C4, 0xECEF, 0xF5F4, 0xECEF, 0xDB08, 0xC943, 0xB8C2, 0x9820, 0x4000, 0x0000, 0xA000, 0xBA25, 0xE4AE, // 0x0070 (112) pixels +0xEDB2, 0xED0F, 0xDB28, 0xC923, 0xB8A1, 0x9820, 0x2800, 0x0000, 0x0000, 0x9800, 0xB0E2, 0xE4AE, 0xF676, 0xED51, 0xE44C, 0xDB48, // 0x0080 (128) pixels +0xD1C4, 0xD163, 0xB922, 0x9020, 0x8923, 0xD42C, 0xF5F4, 0xF676, 0xED91, 0xE48D, 0xDB69, 0xD183, 0xC8C2, 0xB881, 0x8820, 0x0000, // 0x0090 (144) pixels +0x9800, 0xA020, 0xD286, 0xED71, 0xECEF, 0xDB28, 0xD1E4, 0xD1A4, 0xD163, 0xD1E4, 0xD2C7, 0xC328, 0xD4AE, 0xF655, 0xEDD3, 0xECCE, // 0x00A0 (160) pixels +0xDB49, 0xD245, 0xD1A4, 0xC902, 0xC922, 0xC922, 0xA881, 0x7000, 0x9800, 0xA881, 0xDB28, 0xECCE, 0xDB89, 0xD183, 0xD0E2, 0xD0E2, // 0x00B0 (176) pixels +0xD122, 0xD205, 0xDB28, 0xE40B, 0xECCE, 0xECAE, 0xE40B, 0xDAE7, 0xD1A3, 0xD102, 0xD0E2, 0xD122, 0xD1C4, 0xD1C4, 0xB0C2, 0x8840, // 0x00C0 (192) pixels +0xA020, 0xB0E2, 0xDAE7, 0xE40B, 0xDAC7, 0xD143, 0xD122, 0xD122, 0xD123, 0xD1A4, 0xDA46, 0xDAE7, 0xDB48, 0xDB08, 0xDA66, 0xD1C4, // 0x00D0 (208) pixels +0xD143, 0xD122, 0xD102, 0xD163, 0xD205, 0xDA46, 0xB922, 0x8860, 0x9820, 0xB122, 0xDA66, 0xDB28, 0xDA66, 0xD163, 0xD163, 0xD163, // 0x00E0 (224) pixels +0xD163, 0xD183, 0xD1A4, 0xD9C4, 0xD9E4, 0xD9C4, 0xD1A3, 0xD163, 0xD163, 0xD163, 0xD143, 0xD1A3, 0xDA86, 0xDAC7, 0xC163, 0x9061, // 0x00F0 (240) pixels +0x7000, 0xA8E2, 0xDA25, 0xDA45, 0xD9E4, 0xD983, 0xD983, 0xD983, 0xD983, 0xD983, 0xD983, 0xD983, 0xD983, 0xD983, 0xD983, 0xD983, // 0x0100 (256) pixels +0xD983, 0xD983, 0xD983, 0xDA25, 0xE308, 0xE2E7, 0xB963, 0x9081, 0x7000, 0x9881, 0xD9E4, 0xE205, 0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, // 0x0110 (272) pixels +0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, 0xD9C4, 0xE225, 0xE308, 0xEB89, 0xE2A7, 0xA902, 0x90C2, // 0x0120 (288) pixels +0x0000, 0x8840, 0xB943, 0xE205, 0xE245, 0xE245, 0xE225, 0xE204, 0xE1E4, 0xE1E4, 0xE1E4, 0xE1E4, 0xE1E4, 0xE1E4, 0xE1E4, 0xE1E4, // 0x0130 (304) pixels +0xE205, 0xE286, 0xEB28, 0xEBCA, 0xEB69, 0xC1A4, 0xA102, 0x9922, 0x0000, 0x0000, 0xA0E2, 0xC183, 0xEA86, 0xEAA7, 0xEAA6, 0xEA66, // 0x0140 (320) pixels +0xEA45, 0xEA25, 0xEA25, 0xEA25, 0xEA25, 0xEA25, 0xEA25, 0xEA86, 0xEB08, 0xEB89, 0xEBEB, 0xEB69, 0xC9E4, 0xA963, 0xA1E4, 0x9922, // 0x0150 (336) pixels +0x0000, 0x0000, 0x9922, 0xA142, 0xB963, 0xE286, 0xF308, 0xEAE7, 0xEAA7, 0xEA86, 0xEA66, 0xEA46, 0xEA46, 0xEA66, 0xEAC7, 0xEB49, // 0x0160 (352) pixels +0xF3CA, 0xF3EB, 0xE328, 0xB9A4, 0xA9C4, 0xAA65, 0xA1C4, 0x88A1, 0x0000, 0x0000, 0x0000, 0xA1A3, 0xA1C4, 0xB163, 0xD225, 0xEB08, // 0x0170 (368) pixels +0xF308, 0xF2C7, 0xF2A7, 0xF2A6, 0xF2C7, 0xF328, 0xF3AA, 0xF40B, 0xF3CA, 0xD286, 0xB1A3, 0xB286, 0xB2C6, 0xAA24, 0x9922, 0x0000, // 0x0180 (384) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0xA1A3, 0xAA65, 0xA9C4, 0xB9A4, 0xE2C7, 0xF328, 0xF308, 0xF308, 0xF349, 0xF3CA, 0xFC2C, 0xEB89, // 0x0190 (400) pixels +0xC1E4, 0xB225, 0xBB28, 0xB2C6, 0xAA24, 0x9922, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x9922, 0xAA45, 0xAA45, // 0x01A0 (416) pixels +0xB183, 0xDA86, 0xFB48, 0xFB89, 0xFBEB, 0xFC2C, 0xE348, 0xB1C4, 0xBAC7, 0xBB28, 0xB286, 0xA1C4, 0x90A1, 0x0000, 0x0000, 0x0000, // 0x01B0 (432) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8881, 0xA1C4, 0xAA65, 0xA983, 0xDA66, 0xFB69, 0xFBCA, 0xE328, 0xB1A4, 0xBB08, // 0x01C0 (448) pixels +0xB2E7, 0xAA45, 0x9942, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01D0 (464) pixels +0x9122, 0xAA25, 0xA983, 0xE2C7, 0xEB28, 0xB1C4, 0xBB07, 0xB2C6, 0xA9E4, 0x88C1, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01E0 (480) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xAA04, 0xA9A4, 0xB1E4, 0xBAE7, 0xB2C6, 0xA1E4, // 0x01F0 (496) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0200 (512) pixels +0x0000, 0x0000, 0x0000, 0xA1C4, 0xAA24, 0xB2E7, 0xA204, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0210 (528) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x9102, 0xA1E4, 0xA1C3, 0x80A1, 0x0000, // 0x0220 (544) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x8040, 0x7820, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels +}; diff --git a/examples/MatrixGFXDemo/yellowsmiley24.h b/examples/MatrixGFXDemo/yellowsmiley24.h new file mode 100644 index 0000000..8b6238b --- /dev/null +++ b/examples/MatrixGFXDemo/yellowsmiley24.h @@ -0,0 +1,46 @@ +// Generated by : UTFTConverter v0.1 +// Generated from : yellowsmiley24.jpg +// Time generated : 2017-04-23 04:26:54.705142 UTC +// Image Size : 24x24 pixels +// Memory usage : 1152 bytes + +#include + +const unsigned short heart[576] PROGMEM={ +0x0801, 0x0800, 0x0800, 0x0000, 0x0000, 0x0040, 0x1880, 0x6122, 0x82A1, 0xA3C4, 0xBC65, 0xC4A5, 0xCCA6, 0xBC45, 0xA383, 0x8280, // 0x0010 (16) pixels +0x5101, 0x1040, 0x0060, 0x0000, 0x0801, 0x0800, 0x0000, 0x0000, 0x0000, 0x0040, 0x0020, 0x0001, 0x1840, 0x61E0, 0xABC2, 0xD5CA, // 0x0020 (32) pixels +0xF711, 0xFFB4, 0xFFF8, 0xFFF9, 0xFFF9, 0xFFF8, 0xFF74, 0xF6F1, 0xCD68, 0xA382, 0x5160, 0x1881, 0x0001, 0x0020, 0x0040, 0x0001, // 0x0030 (48) pixels +0x0000, 0x0020, 0x0020, 0x2880, 0x8AA2, 0xD527, 0xFF51, 0xFFB7, 0xFFD7, 0xFFB5, 0xFFB5, 0xFF93, 0xFF73, 0xFF74, 0xFF95, 0xFF96, // 0x0040 (64) pixels +0xFF57, 0xFED0, 0xCC86, 0x7AA1, 0x18A0, 0x0000, 0x0020, 0x0020, 0x0800, 0x0803, 0x28C0, 0x9340, 0xE549, 0xFF56, 0xFFF7, 0xFF92, // 0x0050 (80) pixels +0xFF92, 0xFF71, 0xFF50, 0xFF70, 0xFF70, 0xFF30, 0xFF51, 0xFF31, 0xFF53, 0xFF97, 0xFF15, 0xD4C6, 0x82E0, 0x2861, 0x0802, 0x0000, // 0x0060 (96) pixels +0x0021, 0x2060, 0x8280, 0xDD69, 0xFF75, 0xFF52, 0xFF8F, 0xFF70, 0xFF50, 0xFF50, 0xFF91, 0xF750, 0xFF90, 0xFF70, 0xFF10, 0xFEF0, // 0x0070 (112) pixels +0xFECE, 0xFF30, 0xF712, 0xFED3, 0xD4C7, 0x7AA0, 0x1860, 0x0802, 0x0020, 0x61E0, 0xC465, 0xFF10, 0xFFB1, 0xFF4F, 0xFF0F, 0xFF51, // 0x0080 (128) pixels +0xFF4E, 0xFF30, 0xFF11, 0xE5CD, 0xF66F, 0xFF30, 0xFEEF, 0xFF0F, 0xFED0, 0xFEAF, 0xFEED, 0xFEF0, 0xFE70, 0xB3E3, 0x5A00, 0x0820, // 0x0090 (144) pixels +0x3081, 0xA381, 0xFE6C, 0xFF13, 0xFF10, 0xFEEE, 0xFF2F, 0xFF4E, 0xFF2E, 0xFF0F, 0xDE0D, 0xBCC9, 0xE62D, 0xFEEF, 0xFEEE, 0xFEEE, // 0x00A0 (160) pixels +0xFEEE, 0xF6AF, 0xFE6C, 0xFE6E, 0xFE94, 0xEDAB, 0x9B40, 0x2060, 0x7220, 0xBCA6, 0xFECD, 0xFEEF, 0xFECD, 0xFF2E, 0xFEEE, 0xFEEE, // 0x00B0 (176) pixels +0xFEED, 0xFEAE, 0xC4A8, 0xBC88, 0xFEAF, 0xFECE, 0xFECE, 0xFE8D, 0xFE6D, 0xFE6E, 0xFE8E, 0xFE6C, 0xFE2D, 0xFE8E, 0xAC44, 0x71A1, // 0x00C0 (192) pixels +0x8B01, 0xED49, 0xFE8C, 0xFEEC, 0xFECD, 0xFEAD, 0xFECD, 0xFECD, 0xFEED, 0xEE0C, 0xB3E6, 0xDD6A, 0xFE8B, 0xFE8B, 0xFEAC, 0xFE4C, // 0x00D0 (208) pixels +0xCCEA, 0xEDAB, 0xFE6B, 0xFE2B, 0xFE0D, 0xFE0D, 0xD4A7, 0x8AE0, 0x9341, 0xF5AA, 0xFEAD, 0xFE8B, 0xFE8B, 0xFE6B, 0xFE4A, 0xFE68, // 0x00E0 (224) pixels +0xFE47, 0xCCC2, 0xB3A0, 0xFDE7, 0xFDE5, 0xFE05, 0xF5E6, 0xCC84, 0xA363, 0xED89, 0xFE09, 0xFE0A, 0xFDEB, 0xFDCB, 0xE549, 0x9320, // 0x00F0 (240) pixels +0x9BA1, 0xFDA9, 0xFE4B, 0xFE4A, 0xFE48, 0xF5A7, 0xD482, 0xFE24, 0xFDE5, 0xFDE5, 0xFDE4, 0xFDE5, 0xFDC4, 0xFDE4, 0xF585, 0xA2C0, // 0x0100 (256) pixels +0xAB20, 0xFD67, 0xFD86, 0xFDA7, 0xFDC9, 0xFDA9, 0xED89, 0x9340, 0x9360, 0xFDC8, 0xFE0A, 0xFDE8, 0xFDE5, 0xFDC7, 0xBB80, 0xFDE4, // 0x0110 (272) pixels +0xFDC6, 0xFDE6, 0xFD84, 0xFDC5, 0xFDE6, 0xFDA5, 0xD463, 0xA2E1, 0xD442, 0xFD45, 0xFD44, 0xFD45, 0xFD46, 0xFD67, 0xED27, 0x9B40, // 0x0120 (288) pixels +0x9B61, 0xFD67, 0xFDA7, 0xFDA5, 0xFDA3, 0xFDE7, 0xCC02, 0xF584, 0xFDC5, 0xFDA6, 0xFDA5, 0xFDA4, 0xFDA4, 0xFD85, 0xE4C4, 0xC3C0, // 0x0130 (304) pixels +0xFD45, 0xFD23, 0xFD23, 0xFD24, 0xFCC4, 0xFD05, 0xECC5, 0xA361, 0x9B62, 0xECC4, 0xFD44, 0xFD84, 0xFD83, 0xF564, 0xE4C5, 0xCC42, // 0x0140 (320) pixels +0xFD63, 0xFD64, 0xFD85, 0xFD63, 0xFD84, 0xFD24, 0xFD65, 0xFD43, 0xFD44, 0xFD23, 0xFD03, 0xFD04, 0xFCA3, 0xFCA3, 0xE484, 0x9B21, // 0x0150 (336) pixels +0x9341, 0xE463, 0xFD64, 0xFD44, 0xFD44, 0xFD64, 0xFD66, 0xCBE2, 0xECE4, 0xFD86, 0xFD24, 0xFD44, 0xFD23, 0xFD45, 0xFD04, 0xFD24, // 0x0160 (352) pixels +0xFD04, 0xFCE3, 0xFCC3, 0xFCC4, 0xFCA3, 0xFC82, 0xD423, 0x8AE0, 0x8B40, 0xCBC0, 0xF502, 0xFD04, 0xFD25, 0xFD43, 0xFD44, 0xF506, // 0x0170 (368) pixels +0xBB80, 0xDC82, 0xF523, 0xFD44, 0xFD25, 0xFD04, 0xFD04, 0xFCE4, 0xF483, 0xFCA3, 0xFCA4, 0xFC83, 0xFC82, 0xF462, 0xBBA1, 0x8B00, // 0x0180 (384) pixels +0x72E0, 0xB341, 0xECA3, 0xFCE3, 0xFCC4, 0xFD03, 0xFD04, 0xFD44, 0xF527, 0xDC64, 0xCC02, 0xCC22, 0xCC22, 0xD402, 0xD422, 0xDC23, // 0x0190 (400) pixels +0xD402, 0xEC42, 0xFC42, 0xFC64, 0xEC82, 0xDC42, 0xA322, 0x7AC0, 0x61A1, 0x8320, 0xD402, 0xFC82, 0xFD05, 0xFCE4, 0xFCE1, 0xFCE3, // 0x01A0 (416) pixels +0xFD05, 0xFCE5, 0xF4E6, 0xFCE7, 0xFCC6, 0xFCC5, 0xF4A4, 0xF483, 0xFC83, 0xFC83, 0xFCA4, 0xF442, 0xFC23, 0xD3E2, 0x8300, 0x4900, // 0x01B0 (432) pixels +0x1840, 0x82E2, 0x9B20, 0xDC03, 0xFC82, 0xF4C3, 0xFCA3, 0xFC83, 0xFCA2, 0xFCA3, 0xFCC3, 0xFCA2, 0xFC82, 0xFC82, 0xFC82, 0xFC62, // 0x01C0 (448) pixels +0xFC43, 0xFC63, 0xEC42, 0xFC42, 0xD3C1, 0x8B20, 0x7AA2, 0x1840, 0x0020, 0x4980, 0x9320, 0xA361, 0xDC23, 0xFCA2, 0xFCA4, 0xFC85, // 0x01D0 (464) pixels +0xFC84, 0xFC83, 0xFC83, 0xFC82, 0xFC62, 0xFC63, 0xFC63, 0xFC44, 0xFC24, 0xFC62, 0xFC21, 0xDBC3, 0x9B60, 0x8300, 0x4181, 0x0800, // 0x01E0 (480) pixels +0x0000, 0x1041, 0x6A61, 0x8B00, 0xA360, 0xD3E3, 0xF463, 0xF482, 0xFC82, 0xFC62, 0xFC43, 0xFC43, 0xFC23, 0xFC43, 0xFC22, 0xFC22, // 0x01F0 (496) pixels +0xFC82, 0xEC03, 0xCB81, 0xA380, 0x9340, 0x6A00, 0x0020, 0x0000, 0x0000, 0x0000, 0x0800, 0x6A62, 0x8B00, 0x9B41, 0xBB81, 0xDC41, // 0x0200 (512) pixels +0xEC62, 0xFCA3, 0xFCC3, 0xFC82, 0xFC62, 0xFC83, 0xFC83, 0xEC62, 0xD400, 0xC381, 0x9341, 0x8B00, 0x6201, 0x0821, 0x0000, 0x0020, // 0x0210 (528) pixels +0x0001, 0x0020, 0x0001, 0x0821, 0x59C0, 0x8B01, 0x8B40, 0xAB00, 0xB341, 0xBBA2, 0xCBE2, 0xCC01, 0xCBE1, 0xCBC1, 0xBBA2, 0xB341, // 0x0220 (544) pixels +0xA321, 0x8B40, 0x82E1, 0x5180, 0x0840, 0x0001, 0x0020, 0x0001, 0x0000, 0x0002, 0x0000, 0x0020, 0x0800, 0x3080, 0x7201, 0x8340, // 0x0230 (560) pixels +0x8B40, 0x8B20, 0x9320, 0x9B40, 0x9B40, 0x9340, 0x8B40, 0x8B20, 0x8300, 0x6A22, 0x2880, 0x0020, 0x0000, 0x0800, 0x0001, 0x0000, // 0x0240 (576) pixels +}; From f237633a478760827465b7790b17b4498ae249f6 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sun, 23 Apr 2017 09:02:12 -0700 Subject: [PATCH 09/15] Cleanups: moved all display demos back to individual functions. Re-added circles demo that wasn't being called. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 309 +++++++++++------------ examples/MatrixGFXDemo/bluesmiley24.h | 2 +- examples/MatrixGFXDemo/heart24.h | 2 +- examples/MatrixGFXDemo/yellowsmiley24.h | 2 +- 4 files changed, 156 insertions(+), 159 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 0242a65..81f6ed0 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -5,6 +5,8 @@ #include #include #include + +// Choose your prefered pixmap //#include "heart24.h" #include "yellowsmiley24.h" //#include "bluesmiley24.h" @@ -14,16 +16,9 @@ #define PIN 6 -typedef enum { - FOUR_WHITE = 0, - BITMAP = 1, - RGB_BITMAP = 2, - LINES = 3, - BOXES = 4, - CIRCLES = 5, - SCROLLTEXT = 6, - BOUNCE_BITMAP = 7, -} MatrixDisplay; +// Define matrix height and width. +uint16_t mw = 12; +uint16_t mh = 12; // MATRIX DECLARATION: // Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display) @@ -59,14 +54,11 @@ typedef enum { // NEO_KHZ400 400 KHz bitstream (e.g. FLORA v1 pixels) // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) -Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(24, 24, PIN, +Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(mw, mh, PIN, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800); -uint16_t mw = matrix->width(); -uint16_t mh = matrix->height(); - // This could also be defined as matrix->color(255,0,0) but those defines // are meant to work for adafruit_gfx backends that are lacking color() #define LED_BLACK 0 @@ -331,207 +323,212 @@ void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, i matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h, false); } -void display_matrix(MatrixDisplay choice, uint8_t bmp_num=0, uint16_t color=0) { +// Fill the screen with multiple levels of white to gauge the quality +void display_four_white() { + matrix->clear(); + matrix->fillRect(0,0, mw,mh, LED_WHITE_HIGH); + matrix->drawRect(1,1, mw-2,mh-2, LED_WHITE_MEDIUM); + matrix->drawRect(2,2, mw-4,mh-4, LED_WHITE_LOW); + matrix->drawRect(3,3, mw-6,mh-6, LED_WHITE_VERYLOW); + matrix->show(); +} + +void display_bitmap(uint8_t bmp_num, uint16_t color) { static uint16_t bmx,bmy; - switch (choice) { - - case FOUR_WHITE: - matrix->clear(); - matrix->fillRect(0,0, mw,mh, LED_WHITE_HIGH); - matrix->drawRect(1,1, mw-2,mh-2, LED_WHITE_MEDIUM); - matrix->drawRect(2,2, mw-4,mh-4, LED_WHITE_LOW); - matrix->drawRect(3,3, mw-6,mh-6, LED_WHITE_VERYLOW); - break; - - case BITMAP: - // Clear the space under the bitmap that will be drawn as - // drawing a single color pixmap does not write over pixels - // that are nul, and leaves the data that was underneath - matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK); - matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); - bmx += 8; - if (bmx > mw) bmx = 0; - if (!bmx) bmy += 8; - if (bmy > mh) bmy = 0; - break; - - case RGB_BITMAP: - fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8); - bmx += 8; - if (bmx > mw) bmx = 0; - if (!bmx) bmy += 8; - if (bmy > mh) bmy = 0; - break; - - case LINES: - matrix->clear(); + // Clear the space under the bitmap that will be drawn as + // drawing a single color pixmap does not write over pixels + // that are nul, and leaves the data that was underneath + matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK); + matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); + bmx += 8; + if (bmx > mw) bmx = 0; + if (!bmx) bmy += 8; + if (bmy > mh) bmy = 0; + matrix->show(); +} - // 4 levels of crossing red lines. - matrix->drawLine(0,mh/2-2, mw-1,2, LED_RED_VERYLOW); - matrix->drawLine(0,mh/2-1, mw-1,3, LED_RED_LOW); - matrix->drawLine(0,mh/2, mw-1,mh/2, LED_RED_MEDIUM); - matrix->drawLine(0,mh/2+1, mw-1,mh/2+1, LED_RED_HIGH); +void display_rgbBitmap(uint8_t bmp_num) { + static uint16_t bmx,bmy; - // 4 levels of crossing green lines. - matrix->drawLine(mw/2-2, 0, mw/2-2, mh-1, LED_GREEN_VERYLOW); - matrix->drawLine(mw/2-1, 0, mw/2-1, mh-1, LED_GREEN_LOW); - matrix->drawLine(mw/2+0, 0, mw/2+0, mh-1, LED_GREEN_MEDIUM); - matrix->drawLine(mw/2+1, 0, mw/2+1, mh-1, LED_GREEN_HIGH); + fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8); + bmx += 8; + if (bmx > mw) bmx = 0; + if (!bmx) bmy += 8; + if (bmy > mh) bmy = 0; + matrix->show(); +} - // Diagonal blue line. - matrix->drawLine(0,0, mw-1,mh-1, LED_BLUE_HIGH); - matrix->drawLine(0,mh-1, mw-1,0, LED_ORANGE_MEDIUM); - break; +void display_lines() { + matrix->clear(); - case BOXES: - matrix->clear(); - matrix->drawRect(0,0, mw,mh, LED_BLUE_HIGH); - matrix->drawRect(1,1, mw-2,mh-2, LED_GREEN_MEDIUM); - matrix->fillRect(2,2, mw-4,mh-4, LED_RED_HIGH); - matrix->fillRect(3,3, mw-6,mh-6, LED_ORANGE_MEDIUM); - break; - - case CIRCLES: - matrix->clear(); - matrix->drawCircle(mw/2,mh/2, 2, LED_RED_MEDIUM); - matrix->drawCircle(mw/2-3,mh/2-3, 2, LED_BLUE_HIGH); - matrix->drawCircle(1,mh-2, 1, LED_GREEN_LOW); - matrix->drawCircle(mw-2,1, 1, LED_GREEN_HIGH); - break; + // 4 levels of crossing red lines. + matrix->drawLine(0,mh/2-2, mw-1,2, LED_RED_VERYLOW); + matrix->drawLine(0,mh/2-1, mw-1,3, LED_RED_LOW); + matrix->drawLine(0,mh/2, mw-1,mh/2, LED_RED_MEDIUM); + matrix->drawLine(0,mh/2+1, mw-1,mh/2+1, LED_RED_HIGH); + + // 4 levels of crossing green lines. + matrix->drawLine(mw/2-2, 0, mw/2-2, mh-1, LED_GREEN_VERYLOW); + matrix->drawLine(mw/2-1, 0, mw/2-1, mh-1, LED_GREEN_LOW); + matrix->drawLine(mw/2+0, 0, mw/2+0, mh-1, LED_GREEN_MEDIUM); + matrix->drawLine(mw/2+1, 0, mw/2+1, mh-1, LED_GREEN_HIGH); + + // Diagonal blue line. + matrix->drawLine(0,0, mw-1,mh-1, LED_BLUE_HIGH); + matrix->drawLine(0,mh-1, mw-1,0, LED_ORANGE_MEDIUM); + matrix->show(); +} - case SCROLLTEXT: - matrix->clear(); - matrix->setTextWrap(false); // we don't wrap text so it scrolls nicely - matrix->setTextSize(1); - matrix->setRotation(0); - for (int8_t x=7; x>=-42; x--) { - matrix->clear(); - matrix->setCursor(x,0); - matrix->setTextColor(LED_GREEN_HIGH); - matrix->print("Hello"); - if (mh>11) { - matrix->setCursor(-20-x,min(9, mh-7)); - matrix->setTextColor(LED_ORANGE_HIGH); - matrix->print("World"); - } - matrix->show(); - delay(50); - } +void display_boxes() { + matrix->clear(); + matrix->drawRect(0,0, mw,mh, LED_BLUE_HIGH); + matrix->drawRect(1,1, mw-2,mh-2, LED_GREEN_MEDIUM); + matrix->fillRect(2,2, mw-4,mh-4, LED_RED_HIGH); + matrix->fillRect(3,3, mw-6,mh-6, LED_ORANGE_MEDIUM); + matrix->show(); +} - matrix->setRotation(3); - matrix->setTextColor(LED_BLUE_HIGH); - for (int8_t x=7; x>=-60; x--) { - matrix->clear(); - matrix->setCursor(x,mh/2-4); - matrix->print("Sideways Too!"); - matrix->show(); - delay(50); - } - matrix->setRotation(0); - matrix->setCursor(0,0); - break; - - case BOUNCE_BITMAP: - { - // keep integer math, deal with values 16 times too big - int16_t xf = (mw/2-4) << 4; - int16_t yf = (mh/2-4) << 4; - int16_t xfc = random(16); - int16_t yfc = random(16); - int16_t xfdir = 1; - int16_t yfdir = 1; - - for (uint8_t i=1; i<255; i++) { - bool updDir = false; - - // and then dvide by 16 here. - int16_t x = xf >> 4; - int16_t y = yf >> 4; - - matrix->clear(); - matrix->drawRGBBitmap(x, y, heart, 24, 24, true); - matrix->show(); - - xf += xfc*xfdir; - yf += yfc*yfdir; - // Deal with bouncing off the 'walls' - if (xf >= (mw-8) << 4) { xfdir *= -1; updDir = true ; }; - if (xf <= (mw-24 << 4)) { xfdir *= -1; updDir = true ; }; - if (yf >= (mh-8) << 4) { yfdir *= -1; updDir = true ; }; - if (yf <= (mh-24 << 4)) { yfdir *= -1; updDir = true ; }; - if (updDir) { - // Add -1, 0 or 1 but bind result to 1 to 1. - xfc = constrain(xfc + random(-1, 2), 1, 16); - yfc = constrain(xfc + random(-1, 2), 1, 16); - } - delay(20); - } +void display_circles() { + matrix->clear(); + matrix->drawCircle(mw/2,mh/2, 2, LED_RED_MEDIUM); + matrix->drawCircle(mw/2-3,mh/2-3, 2, LED_BLUE_HIGH); + matrix->drawCircle(mw/2+3,mh/2+3, 2, LED_ORANGE_MEDIUM); + matrix->drawCircle(1,mh-2, 1, LED_GREEN_LOW); + matrix->drawCircle(mw-2,1, 1, LED_GREEN_HIGH); + matrix->show(); +} + +void display_scrollText() { + matrix->clear(); + matrix->setTextWrap(false); // we don't wrap text so it scrolls nicely + matrix->setTextSize(1); + matrix->setRotation(0); + for (int8_t x=7; x>=-42; x--) { + matrix->clear(); + matrix->setCursor(x,0); + matrix->setTextColor(LED_GREEN_HIGH); + matrix->print("Hello"); + if (mh>11) { + matrix->setCursor(-20-x,min(9, mh-7)); + matrix->setTextColor(LED_ORANGE_HIGH); + matrix->print("World"); } - break; + matrix->show(); + delay(50); + } + matrix->setRotation(3); + matrix->setTextColor(LED_BLUE_HIGH); + for (int8_t x=7; x>=-60; x--) { + matrix->clear(); + matrix->setCursor(x,mh/2-4); + matrix->print("Sideways Too!"); + matrix->show(); + delay(50); } + matrix->setRotation(0); + matrix->setCursor(0,0); matrix->show(); } +void display_panBitmap () { + // keep integer math, deal with values 16 times too big + int16_t xf = (mw/2-4) << 4; + int16_t yf = (mh/2-4) << 4; + int16_t xfc = random(16); + int16_t yfc = random(16); + int16_t xfdir = 1; + int16_t yfdir = 1; + + for (uint8_t i=1; i<255; i++) { + bool updDir = false; + + // and then dvide by 16 here. + int16_t x = xf >> 4; + int16_t y = yf >> 4; + + matrix->clear(); + matrix->drawRGBBitmap(x, y, bitmap24, 24, 24, true); + matrix->show(); + + xf += xfc*xfdir; + yf += yfc*yfdir; + // Deal with bouncing off the 'walls' + if (xf >= ((mw-8) << 4)) { xfdir *= -1; updDir = true ; }; + if (xf <= ((mw-24) << 4)) { xfdir *= -1; updDir = true ; }; + if (yf >= ((mh-8) << 4)) { yfdir *= -1; updDir = true ; }; + if (yf <= ((mh-24) << 4)) { yfdir *= -1; updDir = true ; }; + if (updDir) { + // Add -1, 0 or 1 but bind result to 1 to 1. + xfc = constrain(xfc + random(-1, 2), 1, 16); + yfc = constrain(xfc + random(-1, 2), 1, 16); + } + delay(20); + } +} + + void loop() { // clear the screen after X bitmaps have been displayed and we // loop back to the top left corner // 8x8 => 1, 16x8 => 2, 17x9 => 6 static uint8_t pixmap_count = ((mw+7)/8) * ((mh+7)/8); uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH }; - uint16_t scandelay[] = { 5, 50, 200, 1000 }; Serial.print("Screen pixmap capacity: "); Serial.println(pixmap_count); - display_matrix(RGB_BITMAP, 0); // multicolor bitmap sent as many times as we can display an 8x8 pixmap for (uint8_t i=0; i<=pixmap_count; i++) { - display_matrix(RGB_BITMAP, 0); + display_rgbBitmap(0); } // Cycle through red, green, blue, display 2 checkered patterns // useful to debug some screen types and alignment. for (uint8_t i=0; i<3; i++) { - display_matrix(BITMAP, 3 + (i % 2), bmpcolor[i]); + display_bitmap(3 + (i % 2), bmpcolor[i]); delay(500); - display_matrix(BITMAP, 4 - (i % 2), bmpcolor[i]); + display_bitmap(4 - (i % 2), bmpcolor[i]); delay(500); } for (uint8_t i=0; i<=2; i++) { - display_matrix(BITMAP, i, bmpcolor[i]); + display_bitmap(i, bmpcolor[i]); delay(mw>8?500:1500); } // If we have multiple pixmaps displayed at once, wait a bit longer. delay(mw>8?1500:500); - display_matrix(LINES); + display_lines(); delay(3000); - display_matrix(BOXES); + display_boxes(); delay(3000); + display_circles(); + delay(3000); for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) { - display_matrix(RGB_BITMAP, i); + display_rgbBitmap(i); delay(mw>8?500:1500); } - // Fill the screen with multiple levels of white to guage the quality - display_matrix(FOUR_WHITE, 0); + display_four_white(); delay(3000); - display_matrix(SCROLLTEXT); + display_scrollText(); delay(2000); - display_matrix(BOUNCE_BITMAP, 0); + display_panBitmap(); delay(2000); + + //display_matrix(BOUNCE_BITMAP, 0); + //delay(2000); } // vim:sts=4:sw=4 diff --git a/examples/MatrixGFXDemo/bluesmiley24.h b/examples/MatrixGFXDemo/bluesmiley24.h index 71c8201..38e4c73 100644 --- a/examples/MatrixGFXDemo/bluesmiley24.h +++ b/examples/MatrixGFXDemo/bluesmiley24.h @@ -6,7 +6,7 @@ #include -const unsigned short heart[576] PROGMEM={ +const unsigned short bitmap24[576] PROGMEM={ 0x0000, 0x0040, 0x0020, 0x0802, 0x0802, 0x0001, 0x0041, 0x0020, 0x0002, 0x1002, 0x0801, 0x0020, 0x0800, 0x0000, 0x0040, 0x0060, // 0x0010 (16) pixels 0x0800, 0x0000, 0x0001, 0x0001, 0x0800, 0x0800, 0x0000, 0x1000, 0x0020, 0x0000, 0x0000, 0x0042, 0x0020, 0x0000, 0x0801, 0x0000, // 0x0020 (32) pixels 0x0020, 0x0800, 0x0000, 0x0000, 0x2000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0021, 0x0020, 0x0000, 0x0041, 0x0001, 0x0001, 0x0001, // 0x0030 (48) pixels diff --git a/examples/MatrixGFXDemo/heart24.h b/examples/MatrixGFXDemo/heart24.h index ff4796c..fa2c76c 100644 --- a/examples/MatrixGFXDemo/heart24.h +++ b/examples/MatrixGFXDemo/heart24.h @@ -13,7 +13,7 @@ #define PROGMEM #endif -const unsigned short bitmap[576] PROGMEM={ +const unsigned short bitmap24[576] PROGMEM={ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels diff --git a/examples/MatrixGFXDemo/yellowsmiley24.h b/examples/MatrixGFXDemo/yellowsmiley24.h index 8b6238b..04d29b1 100644 --- a/examples/MatrixGFXDemo/yellowsmiley24.h +++ b/examples/MatrixGFXDemo/yellowsmiley24.h @@ -6,7 +6,7 @@ #include -const unsigned short heart[576] PROGMEM={ +const unsigned short bitmap24[576] PROGMEM={ 0x0801, 0x0800, 0x0800, 0x0000, 0x0000, 0x0040, 0x1880, 0x6122, 0x82A1, 0xA3C4, 0xBC65, 0xC4A5, 0xCCA6, 0xBC45, 0xA383, 0x8280, // 0x0010 (16) pixels 0x5101, 0x1040, 0x0060, 0x0000, 0x0801, 0x0800, 0x0000, 0x0000, 0x0000, 0x0040, 0x0020, 0x0001, 0x1840, 0x61E0, 0xABC2, 0xD5CA, // 0x0020 (32) pixels 0xF711, 0xFFB4, 0xFFF8, 0xFFF9, 0xFFF9, 0xFFF8, 0xFF74, 0xF6F1, 0xCD68, 0xA382, 0x5160, 0x1881, 0x0001, 0x0020, 0x0040, 0x0001, // 0x0030 (48) pixels From b0fa5cae6d49f8626db6f71bd443fb794a1fe151 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sun, 23 Apr 2017 13:51:06 -0700 Subject: [PATCH 10/15] Fixed display_panBitmap. Moved setup to the end, small other fixes. Changed smiley to blue one. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 82 ++++++++++++++---------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 81f6ed0..bb2a55f 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -8,14 +8,18 @@ // Choose your prefered pixmap //#include "heart24.h" -#include "yellowsmiley24.h" -//#include "bluesmiley24.h" +//#include "yellowsmiley24.h" +#include "bluesmiley24.h" #ifndef PSTR #define PSTR // Make Arduino Due happy #endif #define PIN 6 +// Max is 255, 32 is a conservative value to not overload +// a USB power supply (500mA) for 12x12 pixels. +#define BRIGHTNESS 64 + // Define matrix height and width. uint16_t mw = 12; uint16_t mh = 12; @@ -273,19 +277,6 @@ static const uint16_t PROGMEM }; -void setup() { - Serial.begin(115200); - matrix->begin(); - matrix->setTextWrap(false); - //matrix->setBrightness(255); - matrix->setBrightness(32); - matrix->fillScreen(LED_ORANGE_HIGH); - matrix->show(); - delay(1000); - matrix->clear(); -} - - // Convert a BGR 4/4/4 bitmap to RGB 5/6/5 used by Adafruit_GFX void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) { uint16_t RGB_bmp_fixed[w * h]; @@ -420,7 +411,7 @@ void display_scrollText() { matrix->setRotation(3); matrix->setTextColor(LED_BLUE_HIGH); - for (int8_t x=7; x>=-60; x--) { + for (int8_t x=7; x>=-80; x--) { matrix->clear(); matrix->setCursor(x,mh/2-4); matrix->print("Sideways Too!"); @@ -432,39 +423,50 @@ void display_scrollText() { matrix->show(); } +// Scroll within big bitmap so that all if it becomes visible. void display_panBitmap () { // keep integer math, deal with values 16 times too big - int16_t xf = (mw/2-4) << 4; - int16_t yf = (mh/2-4) << 4; - int16_t xfc = random(16); - int16_t yfc = random(16); - int16_t xfdir = 1; - int16_t yfdir = 1; - - for (uint8_t i=1; i<255; i++) { + uint8_t panBitmapSize = 24; + + //int16_t xf = (mw/2-4) << 4; + //int16_t yf = (mh/2-4) << 4; + // start by showing upper left of big bitmap + int16_t xf = 0; + int16_t yf = 0; + // scroll speed in 1/16th + int16_t xfc = 6; + int16_t yfc = 3; + // scroll down and right by moving upper left corner off screen + // more up and left (which means negative numbers) + int16_t xfdir = -1; + int16_t yfdir = -1; + + for (uint16_t i=1; i<1000; i++) { bool updDir = false; - // and then dvide by 16 here. + // Get actual x/y by dividing by 16. int16_t x = xf >> 4; int16_t y = yf >> 4; matrix->clear(); - matrix->drawRGBBitmap(x, y, bitmap24, 24, 24, true); + matrix->drawRGBBitmap(x, y, bitmap24, panBitmapSize, panBitmapSize, true); matrix->show(); xf += xfc*xfdir; yf += yfc*yfdir; - // Deal with bouncing off the 'walls' - if (xf >= ((mw-8) << 4)) { xfdir *= -1; updDir = true ; }; - if (xf <= ((mw-24) << 4)) { xfdir *= -1; updDir = true ; }; - if (yf >= ((mh-8) << 4)) { yfdir *= -1; updDir = true ; }; - if (yf <= ((mh-24) << 4)) { yfdir *= -1; updDir = true ; }; + + // we shouldn't display past left corner, reverse direction. + if (xf >= 0) { xfdir = -1; updDir = true ; }; + // we don't go negative past right corner, go back positive + if (xf <= ((mw-panBitmapSize) << 4)) { xfdir = 1; updDir = true ; }; + if (yf >= 0) { yfdir = -1; updDir = true ; }; + if (yf <= ((mh-panBitmapSize) << 4)) { yfdir = 1; updDir = true ; }; if (updDir) { // Add -1, 0 or 1 but bind result to 1 to 1. xfc = constrain(xfc + random(-1, 2), 1, 16); yfc = constrain(xfc + random(-1, 2), 1, 16); } - delay(20); + delay(10); } } @@ -501,7 +503,7 @@ void loop() { delay(mw>8?500:1500); } // If we have multiple pixmaps displayed at once, wait a bit longer. - delay(mw>8?1500:500); + delay(mw>8?1000:500); display_lines(); delay(3000); @@ -522,7 +524,6 @@ void loop() { delay(3000); display_scrollText(); - delay(2000); display_panBitmap(); delay(2000); @@ -531,4 +532,17 @@ void loop() { //delay(2000); } +void setup() { + Serial.begin(115200); + matrix->begin(); + matrix->setTextWrap(false); + matrix->setBrightness(BRIGHTNESS); + // Test full bright of all LEDs. If brightness is too high + // for your current limit (i.e. USB), decrease it. + matrix->fillScreen(LED_WHITE_HIGH); + matrix->show(); + delay(1000); + matrix->clear(); +} + // vim:sts=4:sw=4 From a3610bfb110bbbf19735faad010c2b3b9e683d9e Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sun, 23 Apr 2017 15:11:45 -0700 Subject: [PATCH 11/15] Minor fixes. - changed default pin for esp8266 as well as picture headers. - re-ordered mono patterns - fixed display of multiple bitmaps on screen big enough for multiple ones. - fixed display of 24 pixel bitmap on 24 pixel wide screen --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 112 ++++++++++++----------- examples/MatrixGFXDemo/bluesmiley24.h | 8 +- examples/MatrixGFXDemo/yellowsmiley24.h | 8 +- 3 files changed, 75 insertions(+), 53 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index bb2a55f..848f808 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -16,13 +16,20 @@ #define PIN 6 +// ESP8266 has an I2S neopixel library which can only use pin RX +// so it's recommended to use the same pin with Neopixel to avoid +// rewiring when changing libs +#ifdef ESP8266 +#define PIN RX +#endif + // Max is 255, 32 is a conservative value to not overload // a USB power supply (500mA) for 12x12 pixels. -#define BRIGHTNESS 64 +#define BRIGHTNESS 96 -// Define matrix height and width. -uint16_t mw = 12; -uint16_t mh = 12; +// Define matrix width and height. +#define mw 24 +#define mh 24 // MATRIX DECLARATION: // Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display) @@ -105,8 +112,30 @@ Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(mw, mh, PIN, static const uint8_t PROGMEM mono_bmp[][8] = { + { // 0: checkered 1 + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + }, - { B00111100, + { // 1: checkered 2 + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + }, + + { // 2: smiley + B00111100, B01000010, B10100101, B10000001, @@ -115,7 +144,8 @@ static const uint8_t PROGMEM B01000010, B00111100 }, - { B00111100, + { // 3: neutral + B00111100, B01000010, B10100101, B10000001, @@ -124,7 +154,8 @@ static const uint8_t PROGMEM B01000010, B00111100 }, - { B00111100, + { // 4; frowny + B00111100, B01000010, B10100101, B10000001, @@ -132,28 +163,6 @@ static const uint8_t PROGMEM B10100101, B01000010, B00111100 }, - - { - B10101010, - B01010101, - B10101010, - B01010101, - B10101010, - B01010101, - B10101010, - B01010101, - }, - - { - B01010101, - B10101010, - B01010101, - B10101010, - B01010101, - B10101010, - B01010101, - B10101010, - }, }; static const uint16_t PROGMEM @@ -333,9 +342,9 @@ void display_bitmap(uint8_t bmp_num, uint16_t color) { matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK); matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); bmx += 8; - if (bmx > mw) bmx = 0; + if (bmx >= mw) bmx = 0; if (!bmx) bmy += 8; - if (bmy > mh) bmy = 0; + if (bmy >= mh) bmy = 0; matrix->show(); } @@ -344,9 +353,9 @@ void display_rgbBitmap(uint8_t bmp_num) { fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8); bmx += 8; - if (bmx > mw) bmx = 0; + if (bmx >= mw) bmx = 0; if (!bmx) bmy += 8; - if (bmy > mh) bmy = 0; + if (bmy >= mh) bmy = 0; matrix->show(); } @@ -401,7 +410,7 @@ void display_scrollText() { matrix->setTextColor(LED_GREEN_HIGH); matrix->print("Hello"); if (mh>11) { - matrix->setCursor(-20-x,min(9, mh-7)); + matrix->setCursor(-20-x,mh-7); matrix->setTextColor(LED_ORANGE_HIGH); matrix->print("World"); } @@ -428,11 +437,9 @@ void display_panBitmap () { // keep integer math, deal with values 16 times too big uint8_t panBitmapSize = 24; - //int16_t xf = (mw/2-4) << 4; - //int16_t yf = (mh/2-4) << 4; - // start by showing upper left of big bitmap - int16_t xf = 0; - int16_t yf = 0; + // start by showing upper left of big bitmap or centering if the display is big + int16_t xf = max(0, (mw-panBitmapSize)/2) << 4; + int16_t yf = max(0, (mh-panBitmapSize)/2) << 4; // scroll speed in 1/16th int16_t xfc = 6; int16_t yfc = 3; @@ -441,7 +448,7 @@ void display_panBitmap () { int16_t xfdir = -1; int16_t yfdir = -1; - for (uint16_t i=1; i<1000; i++) { + for (uint16_t i=1; i<500; i++) { bool updDir = false; // Get actual x/y by dividing by 16. @@ -452,8 +459,9 @@ void display_panBitmap () { matrix->drawRGBBitmap(x, y, bitmap24, panBitmapSize, panBitmapSize, true); matrix->show(); - xf += xfc*xfdir; - yf += yfc*yfdir; + // Only pan if the display size is smaller than the pixmap + if (mw= 0) { xfdir = -1; updDir = true ; }; @@ -476,7 +484,6 @@ void loop() { // loop back to the top left corner // 8x8 => 1, 16x8 => 2, 17x9 => 6 static uint8_t pixmap_count = ((mw+7)/8) * ((mh+7)/8); - uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH }; Serial.print("Screen pixmap capacity: "); Serial.println(pixmap_count); @@ -486,23 +493,27 @@ void loop() { { display_rgbBitmap(0); } + delay(1000); // Cycle through red, green, blue, display 2 checkered patterns // useful to debug some screen types and alignment. + uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH }; for (uint8_t i=0; i<3; i++) { - display_bitmap(3 + (i % 2), bmpcolor[i]); + display_bitmap(0, bmpcolor[i]); delay(500); - display_bitmap(4 - (i % 2), bmpcolor[i]); + display_bitmap(1, bmpcolor[i]); delay(500); } - for (uint8_t i=0; i<=2; i++) + // Display 3 smiley faces. + for (uint8_t i=2; i<=4; i++) { - display_bitmap(i, bmpcolor[i]); + display_bitmap(i, bmpcolor[i-2]); + // If more than one pixmap displayed per screen, display more quickly. delay(mw>8?500:1500); } - // If we have multiple pixmaps displayed at once, wait a bit longer. + // If we have multiple pixmaps displayed at once, wait a bit longer on the last. delay(mw>8?1000:500); display_lines(); @@ -519,6 +530,8 @@ void loop() { display_rgbBitmap(i); delay(mw>8?500:1500); } + // If we have multiple pixmaps displayed at once, wait a bit longer on the last. + delay(mw>8?1000:500); display_four_white(); delay(3000); @@ -527,9 +540,6 @@ void loop() { display_panBitmap(); delay(2000); - - //display_matrix(BOUNCE_BITMAP, 0); - //delay(2000); } void setup() { diff --git a/examples/MatrixGFXDemo/bluesmiley24.h b/examples/MatrixGFXDemo/bluesmiley24.h index 38e4c73..be21ec2 100644 --- a/examples/MatrixGFXDemo/bluesmiley24.h +++ b/examples/MatrixGFXDemo/bluesmiley24.h @@ -4,7 +4,13 @@ // Image Size : 24x24 pixels // Memory usage : 1152 bytes -#include +#if defined(__AVR__) + #include +#elif defined(__PIC32MX__) + #define PROGMEM +#elif defined(__arm__) + #define PROGMEM +#endif const unsigned short bitmap24[576] PROGMEM={ 0x0000, 0x0040, 0x0020, 0x0802, 0x0802, 0x0001, 0x0041, 0x0020, 0x0002, 0x1002, 0x0801, 0x0020, 0x0800, 0x0000, 0x0040, 0x0060, // 0x0010 (16) pixels diff --git a/examples/MatrixGFXDemo/yellowsmiley24.h b/examples/MatrixGFXDemo/yellowsmiley24.h index 04d29b1..c69bb33 100644 --- a/examples/MatrixGFXDemo/yellowsmiley24.h +++ b/examples/MatrixGFXDemo/yellowsmiley24.h @@ -4,7 +4,13 @@ // Image Size : 24x24 pixels // Memory usage : 1152 bytes -#include +#if defined(__AVR__) + #include +#elif defined(__PIC32MX__) + #define PROGMEM +#elif defined(__arm__) + #define PROGMEM +#endif const unsigned short bitmap24[576] PROGMEM={ 0x0801, 0x0800, 0x0800, 0x0000, 0x0000, 0x0040, 0x1880, 0x6122, 0x82A1, 0xA3C4, 0xBC65, 0xC4A5, 0xCCA6, 0xBC45, 0xA383, 0x8280, // 0x0010 (16) pixels From 157a066a482acb240d1f593871a50c65c386ad87 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sun, 23 Apr 2017 16:08:21 -0700 Subject: [PATCH 12/15] Added pan and bounce support for pixmaps smaller and bigger than the display. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 58 ++++++++++++++++-------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 848f808..c698722 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -28,8 +28,8 @@ #define BRIGHTNESS 96 // Define matrix width and height. -#define mw 24 -#define mh 24 +#define mw 16 +#define mh 8 // MATRIX DECLARATION: // Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display) @@ -433,13 +433,14 @@ void display_scrollText() { } // Scroll within big bitmap so that all if it becomes visible. -void display_panBitmap () { - // keep integer math, deal with values 16 times too big - uint8_t panBitmapSize = 24; +void display_panOrBounceBitmap (bool pan) { + uint8_t bitmapSize = 8; + if (pan) bitmapSize = 24; + // keep integer math, deal with values 16 times too big // start by showing upper left of big bitmap or centering if the display is big - int16_t xf = max(0, (mw-panBitmapSize)/2) << 4; - int16_t yf = max(0, (mh-panBitmapSize)/2) << 4; + int16_t xf = max(0, (mw-bitmapSize)/2) << 4; + int16_t yf = max(0, (mh-bitmapSize)/2) << 4; // scroll speed in 1/16th int16_t xfc = 6; int16_t yfc = 3; @@ -448,7 +449,7 @@ void display_panBitmap () { int16_t xfdir = -1; int16_t yfdir = -1; - for (uint16_t i=1; i<500; i++) { + for (uint16_t i=1; i<1000; i++) { bool updDir = false; // Get actual x/y by dividing by 16. @@ -456,19 +457,36 @@ void display_panBitmap () { int16_t y = yf >> 4; matrix->clear(); - matrix->drawRGBBitmap(x, y, bitmap24, panBitmapSize, panBitmapSize, true); + // bounce 8x8 tri color smiley face around the screen + if (!pan) fixdrawRGBBitmap(x, y, RGB_bmp[10], 8, 8); + // pan 24x24 pixmap + if (pan) matrix->drawRGBBitmap(x, y, bitmap24, bitmapSize, bitmapSize, true); matrix->show(); // Only pan if the display size is smaller than the pixmap - if (mwbitmapSize) xf += xfc*xfdir; + if (mh>bitmapSize) yf += yfc*yfdir; + } - // we shouldn't display past left corner, reverse direction. - if (xf >= 0) { xfdir = -1; updDir = true ; }; - // we don't go negative past right corner, go back positive - if (xf <= ((mw-panBitmapSize) << 4)) { xfdir = 1; updDir = true ; }; - if (yf >= 0) { yfdir = -1; updDir = true ; }; - if (yf <= ((mh-panBitmapSize) << 4)) { yfdir = 1; updDir = true ; }; + if (pan) { + // we shouldn't display past left corner, reverse direction. + if (xf >= 0) { xfdir = -1; updDir = true ; }; + // we don't go negative past right corner, go back positive + if (xf <= ((mw-bitmapSize) << 4)) { xfdir = 1; updDir = true ; }; + if (yf >= 0) { yfdir = -1; updDir = true ; }; + if (yf <= ((mh-bitmapSize) << 4)) { yfdir = 1; updDir = true ; }; + } else { + // Deal with bouncing off the 'walls' + if (xf >= (mw-8) << 4) { xfdir = -1; updDir = true ; }; + if (xf <= 0) { xfdir = 1; updDir = true ; }; + if (yf >= (mh-8) << 4) { yfdir = -1; updDir = true ; }; + if (yf <= 0) { yfdir = 1; updDir = true ; }; + } if (updDir) { // Add -1, 0 or 1 but bind result to 1 to 1. xfc = constrain(xfc + random(-1, 2), 1, 16); @@ -538,8 +556,10 @@ void loop() { display_scrollText(); - display_panBitmap(); - delay(2000); + // pan a big pixmap + display_panOrBounceBitmap(true); + // bounce around a small one + display_panOrBounceBitmap(false); } void setup() { From c3ddb9fe082f1376f85c29ded3a915c731dd4129 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Mon, 24 Apr 2017 10:39:45 -0700 Subject: [PATCH 13/15] Better darker demo bitmap, added display of resolution. - I hand editted smileytongue24.h to be darker and easier to see, now the default 24x24 bitmap. - New display_resolution demo that shows the resolution if there is enough room on the display. - display_panOrBounceBitmap is now smarter and will automatically adjust to the bitmap size and either pan or bounce depending on the dimensions. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 130 +++++++++++++++++------ examples/MatrixGFXDemo/smileytongue24.h | 52 +++++++++ 2 files changed, 147 insertions(+), 35 deletions(-) create mode 100644 examples/MatrixGFXDemo/smileytongue24.h diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index c698722..72d0f13 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -9,7 +9,8 @@ // Choose your prefered pixmap //#include "heart24.h" //#include "yellowsmiley24.h" -#include "bluesmiley24.h" +//#include "bluesmiley24.h" +#include "smileytongue24.h" #ifndef PSTR #define PSTR // Make Arduino Due happy #endif @@ -28,8 +29,8 @@ #define BRIGHTNESS 96 // Define matrix width and height. -#define mw 16 -#define mh 8 +#define mw 24 +#define mh 24 // MATRIX DECLARATION: // Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display) @@ -392,10 +393,61 @@ void display_boxes() { void display_circles() { matrix->clear(); matrix->drawCircle(mw/2,mh/2, 2, LED_RED_MEDIUM); - matrix->drawCircle(mw/2-3,mh/2-3, 2, LED_BLUE_HIGH); - matrix->drawCircle(mw/2+3,mh/2+3, 2, LED_ORANGE_MEDIUM); + matrix->drawCircle(mw/2-1-min(mw,mh)/8, mh/2-1-min(mw,mh)/8, min(mw,mh)/4, LED_BLUE_HIGH); + matrix->drawCircle(mw/2+1+min(mw,mh)/8, mh/2+1+min(mw,mh)/8, min(mw,mh)/4-1, LED_ORANGE_MEDIUM); matrix->drawCircle(1,mh-2, 1, LED_GREEN_LOW); matrix->drawCircle(mw-2,1, 1, LED_GREEN_HIGH); + if (min(mw,mh)>12) matrix->drawCircle(mw/2-1, mh/2-1, min(mh/2-1,mw/2-1), LED_CYAN_HIGH); + matrix->show(); +} + +void display_resolution() { + // not wide enough; + if (mw<16) return; + matrix->clear(); + // Font is 5x7, if display is too small + // 8 can only display 1 char + // 16 can almost display 3 chars + // 24 can display 4 chars + // 32 can display 5 chars + matrix->setCursor(0, 0); + matrix->setTextColor(matrix->Color(255,0,0)); + if (mw>10) matrix->print(mw/10); + matrix->setTextColor(matrix->Color(255,128,0)); + matrix->print(mw % 10); + matrix->setTextColor(matrix->Color(0,255,0)); + matrix->print('x'); + // not wide enough to print 5 chars, go to next line + if (mw<25) { + if (mh==13) matrix->setCursor(6, 7); + else if (mh>=13) { + matrix->setCursor(mw-11, 8); + } else { + matrix->show(); + delay(2000); + matrix->clear(); + matrix->setCursor(mw-11, 0); + } + } + matrix->setTextColor(matrix->Color(0,255,128)); + matrix->print(mh/10); + matrix->setTextColor(matrix->Color(0,128,255)); + matrix->print(mh % 10); + // enough room for a 2nd line + if (mw>25 && mh >14 || mh>16) { + matrix->setCursor(0, mh-7); + matrix->setTextColor(matrix->Color(0,255,255)); + if (mw>16) matrix->print('*'); + matrix->setTextColor(matrix->Color(255,0,0)); + matrix->print('R'); + matrix->setTextColor(matrix->Color(0,255,0)); + matrix->print('G'); + matrix->setTextColor(matrix->Color(0,0,255)); + matrix->print("B"); + matrix->setTextColor(matrix->Color(255,255,0)); + matrix->print("*"); + } + matrix->show(); } @@ -420,10 +472,10 @@ void display_scrollText() { matrix->setRotation(3); matrix->setTextColor(LED_BLUE_HIGH); - for (int8_t x=7; x>=-80; x--) { + for (int8_t x=7; x>=-45; x--) { matrix->clear(); - matrix->setCursor(x,mh/2-4); - matrix->print("Sideways Too!"); + matrix->setCursor(x,mw/2-4); + matrix->print("Rotate"); matrix->show(); delay(50); } @@ -432,11 +484,10 @@ void display_scrollText() { matrix->show(); } -// Scroll within big bitmap so that all if it becomes visible. -void display_panOrBounceBitmap (bool pan) { - uint8_t bitmapSize = 8; - if (pan) bitmapSize = 24; - +// Scroll within big bitmap so that all if it becomes visible or bounce a small one. +// If the bitmap is bigger in one dimention and smaller in the other one, it will +// be both panned and bounced in the appropriate dimentions. +void display_panOrBounceBitmap (uint8_t bitmapSize) { // keep integer math, deal with values 16 times too big // start by showing upper left of big bitmap or centering if the display is big int16_t xf = max(0, (mw-bitmapSize)/2) << 4; @@ -458,39 +509,43 @@ void display_panOrBounceBitmap (bool pan) { matrix->clear(); // bounce 8x8 tri color smiley face around the screen - if (!pan) fixdrawRGBBitmap(x, y, RGB_bmp[10], 8, 8); + if (bitmapSize == 8) fixdrawRGBBitmap(x, y, RGB_bmp[10], 8, 8); // pan 24x24 pixmap - if (pan) matrix->drawRGBBitmap(x, y, bitmap24, bitmapSize, bitmapSize, true); + if (bitmapSize == 24) matrix->drawRGBBitmap(x, y, bitmap24, bitmapSize, bitmapSize, true); matrix->show(); // Only pan if the display size is smaller than the pixmap - if (pan) { - if (mwbitmapSize) xf += xfc*xfdir; - if (mh>bitmapSize) yf += yfc*yfdir; - } - - if (pan) { - // we shouldn't display past left corner, reverse direction. - if (xf >= 0) { xfdir = -1; updDir = true ; }; + // but not if the difference is too small or it'll look bad. + if (bitmapSize-mw>2) { + if (mw>9) xf += xfc*xfdir; + if (xf >= 0) { xfdir = -1; updDir = true ; }; // we don't go negative past right corner, go back positive if (xf <= ((mw-bitmapSize) << 4)) { xfdir = 1; updDir = true ; }; - if (yf >= 0) { yfdir = -1; updDir = true ; }; + } + if (bitmapSize-mh>2) { + yf += yfc*yfdir; + // we shouldn't display past left corner, reverse direction. + if (yf >= 0) { yfdir = -1; updDir = true ; }; if (yf <= ((mh-bitmapSize) << 4)) { yfdir = 1; updDir = true ; }; - } else { + } + // only bounce a pixmap if it's smaller than the display size + if (mw>bitmapSize) { + xf += xfc*xfdir; // Deal with bouncing off the 'walls' - if (xf >= (mw-8) << 4) { xfdir = -1; updDir = true ; }; + if (xf >= (mw-bitmapSize) << 4) { xfdir = -1; updDir = true ; }; if (xf <= 0) { xfdir = 1; updDir = true ; }; - if (yf >= (mh-8) << 4) { yfdir = -1; updDir = true ; }; + } + if (mh>bitmapSize) { + yf += yfc*yfdir; + if (yf >= (mh-bitmapSize) << 4) { yfdir = -1; updDir = true ; }; if (yf <= 0) { yfdir = 1; updDir = true ; }; } + if (updDir) { // Add -1, 0 or 1 but bind result to 1 to 1. - xfc = constrain(xfc + random(-1, 2), 1, 16); - yfc = constrain(xfc + random(-1, 2), 1, 16); + // Let's take 3 is a minimum speed, otherwise it's too slow. + xfc = constrain(xfc + random(-1, 2), 3, 16); + yfc = constrain(xfc + random(-1, 2), 3, 16); } delay(10); } @@ -505,6 +560,7 @@ void loop() { Serial.print("Screen pixmap capacity: "); Serial.println(pixmap_count); + delay(3000); // multicolor bitmap sent as many times as we can display an 8x8 pixmap for (uint8_t i=0; i<=pixmap_count; i++) @@ -513,6 +569,9 @@ void loop() { } delay(1000); + display_resolution(); + delay(3000); + // Cycle through red, green, blue, display 2 checkered patterns // useful to debug some screen types and alignment. uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH }; @@ -541,6 +600,7 @@ void loop() { delay(3000); display_circles(); + matrix->clear(); delay(3000); for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) @@ -557,9 +617,9 @@ void loop() { display_scrollText(); // pan a big pixmap - display_panOrBounceBitmap(true); + display_panOrBounceBitmap(24); // bounce around a small one - display_panOrBounceBitmap(false); + display_panOrBounceBitmap(8); } void setup() { diff --git a/examples/MatrixGFXDemo/smileytongue24.h b/examples/MatrixGFXDemo/smileytongue24.h new file mode 100644 index 0000000..8a8814c --- /dev/null +++ b/examples/MatrixGFXDemo/smileytongue24.h @@ -0,0 +1,52 @@ +// Generated by : UTFTConverter v0.1 +// Generated from : smiley_tongue_24.jpg +// Time generated : 2017-04-24 16:31:50.352856 UTC +// Image Size : 24x24 pixels +// Memory usage : 1152 bytes + +#if defined(__AVR__) + #include +#elif defined(__PIC32MX__) + #define PROGMEM +#elif defined(__arm__) + #define PROGMEM +#endif + +const unsigned short bitmap24[576] PROGMEM={ +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels +0x0000, 0x0000, 0x4207, 0xFFDD, 0xCE57, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFBB, 0xFF56, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE564, 0xFF99, // 0x0040 (64) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xAD33, 0xF6D1, 0xE501, // 0x0050 (80) pixels +0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xFF9A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0xFFBB, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, // 0x0070 (112) pixels +0xE501, 0xE501, 0xFF57, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFDC, 0xE501, 0xE501, 0xDD01, 0xE501, // 0x0080 (128) pixels +0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xDD01, 0xE501, 0xE501, 0xFF78, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0090 (144) pixels +0x0000, 0x0000, 0x0000, 0xE501, 0xDD01, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE502, 0xE501, 0xE501, 0xDD01, 0xDD01, 0xE501, // 0x00A0 (160) pixels +0xE501, 0xDD01, 0xE501, 0xE501, 0xE501, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFF99, 0xE501, 0xE502, 0xE501, 0x4A69, 0x4A6A, // 0x00B0 (176) pixels +0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE502, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xDD01, 0x0000, 0x0000, 0x0000, // 0x00C0 (192) pixels +0x0000, 0x0000, 0xE501, 0xE501, 0xE501, 0x0000, 0x0000, 0x0000, 0x0000, 0x94B2, 0xE501, 0xE502, 0xE501, 0xE501, 0xE501, 0xE501, // 0x00D0 (208) pixels +0xDD01, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0x0000, 0x0000, 0x0000, 0xFFDC, 0xE501, 0xE501, 0xE501, 0x0000, 0x4A69, 0xE502, // 0x00E0 (224) pixels +0x4A69, 0x0000, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0x4A69, 0x0000, 0x0000, 0xE501, 0xE501, 0xE501, 0xFF58, 0x0000, 0x0000, // 0x00F0 (240) pixels +0x0000, 0xFF9A, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0x94B3, 0xE501, 0xE501, 0xE501, 0xE502, 0x0000, 0x0000, // 0x0100 (256) pixels +0x4A69, 0x0000, 0x0000, 0xE501, 0xE501, 0xE5A7, 0x0000, 0x0000, 0x0000, 0xFF79, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xDD01, // 0x0110 (272) pixels +0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE502, 0x94B2, 0xE501, 0xE501, 0xE501, 0x0000, 0xDD01, 0xDD01, 0xE501, 0x0000, 0x0000, // 0x0120 (288) pixels +0x0000, 0xFF79, 0xE501, 0xE501, 0xFE31, 0xFD91, 0xF5B0, 0xF5F1, 0xF5EC, 0xE501, 0xDD01, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, // 0x0130 (304) pixels +0xE501, 0xE501, 0xE501, 0xE502, 0xE501, 0xE501, 0x0000, 0x0000, 0x0000, 0xFF9A, 0xE501, 0xE501, 0xFE31, 0xF4D0, 0xF800, 0xF800, // 0x0140 (320) pixels +0xF800, 0xDC4D, 0xE4AE, 0xE50F, 0xED90, 0xFE52, 0xE501, 0xE501, 0xE502, 0xE501, 0xE501, 0xE501, 0xE501, 0xEDA7, 0x0000, 0x0000, // 0x0150 (336) pixels +0x0000, 0xFFDC, 0xE501, 0xE501, 0xED66, 0xE48E, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xDBAC, 0xE40D, 0xF4F0, 0xF4F0, 0xF530, // 0x0160 (352) pixels +0xFD91, 0xE501, 0xE501, 0xE501, 0xE501, 0xFF57, 0x0000, 0x0000, 0x0000, 0x0000, 0xE501, 0xE501, 0xE501, 0xF800, 0xF800, 0xF800, // 0x0170 (368) pixels +0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF4F0, 0xFDB1, 0xDD01, 0xE501, 0xE501, 0xE501, 0xE501, 0x0000, 0x0000, // 0x0180 (384) pixels +0x0000, 0x0000, 0xFF78, 0xE501, 0xED70, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF550, // 0x0190 (400) pixels +0xE501, 0xE501, 0xDD01, 0xE501, 0xE501, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xE501, 0xE50E, 0xF800, 0xF800, 0xF800, // 0x01A0 (416) pixels +0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF4F0, 0xF550, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0x0000, 0x0000, 0x0000, // 0x01B0 (432) pixels +0x0000, 0x0000, 0x0000, 0xFFBC, 0xED90, 0xDC0D, 0xE30A, 0xF800, 0xF800, 0xDC0C, 0xE46E, 0xF510, 0xF570, 0xFE11, 0xE501, 0xE502, // 0x01C0 (448) pixels +0xDD01, 0xE501, 0xE501, 0xFF77, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFF7A, 0xE4AE, 0xE3CB, 0xE36A, // 0x01D0 (464) pixels +0xDBCC, 0xDC8E, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xFF57, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01E0 (480) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFF9C, 0xEDD2, 0xED2F, 0xEDB0, 0xDD01, 0xE501, 0xE501, 0xDD01, 0xE501, 0xE521, 0xE501, // 0x01F0 (496) pixels +0xE501, 0xFF99, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFBB, // 0x0200 (512) pixels +0xFF55, 0xE501, 0xE501, 0xE501, 0xE501, 0xE502, 0xE501, 0xFF79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0210 (528) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xEF5B, 0xE501, 0xE501, 0x2103, 0x0000, 0x0000, // 0x0220 (544) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels +}; From 2220456e2d60e591a3482af5c41204ff0ce24a49 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Mon, 24 Apr 2017 10:52:43 -0700 Subject: [PATCH 14/15] remove dead delay. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index 72d0f13..c133b85 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -485,8 +485,8 @@ void display_scrollText() { } // Scroll within big bitmap so that all if it becomes visible or bounce a small one. -// If the bitmap is bigger in one dimention and smaller in the other one, it will -// be both panned and bounced in the appropriate dimentions. +// If the bitmap is bigger in one dimension and smaller in the other one, it will +// be both panned and bounced in the appropriate dimensions. void display_panOrBounceBitmap (uint8_t bitmapSize) { // keep integer math, deal with values 16 times too big // start by showing upper left of big bitmap or centering if the display is big @@ -560,7 +560,6 @@ void loop() { Serial.print("Screen pixmap capacity: "); Serial.println(pixmap_count); - delay(3000); // multicolor bitmap sent as many times as we can display an 8x8 pixmap for (uint8_t i=0; i<=pixmap_count; i++) From ee727356ff471bbd81becd65c347d764bbdde7e6 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sat, 6 May 2017 11:06:25 -0700 Subject: [PATCH 15/15] Support the modified upstream Adafruit::GFX drawRGBBitmap interface. --- examples/MatrixGFXDemo/MatrixGFXDemo.ino | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/MatrixGFXDemo/MatrixGFXDemo.ino b/examples/MatrixGFXDemo/MatrixGFXDemo.ino index c133b85..c1c10b3 100644 --- a/examples/MatrixGFXDemo/MatrixGFXDemo.ino +++ b/examples/MatrixGFXDemo/MatrixGFXDemo.ino @@ -318,10 +318,7 @@ void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, i //Serial.print(" -> "); //Serial.println(RGB_bmp_fixed[pixel], HEX); } - // Non color fixed, progmem read. - //matrix->drawRGBBitmap(x, y, bitmap, w, h, true); - // Color fixed, direct read from RAM. - matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h, false); + matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h); } // Fill the screen with multiple levels of white to gauge the quality @@ -511,7 +508,7 @@ void display_panOrBounceBitmap (uint8_t bitmapSize) { // bounce 8x8 tri color smiley face around the screen if (bitmapSize == 8) fixdrawRGBBitmap(x, y, RGB_bmp[10], 8, 8); // pan 24x24 pixmap - if (bitmapSize == 24) matrix->drawRGBBitmap(x, y, bitmap24, bitmapSize, bitmapSize, true); + if (bitmapSize == 24) matrix->drawRGBBitmap(x, y, (const uint16_t *) bitmap24, bitmapSize, bitmapSize); matrix->show(); // Only pan if the display size is smaller than the pixmap