Port Panel GFX demo.

This commit is contained in:
Marc MERLIN 2018-12-25 02:54:55 -08:00
parent 137da49f80
commit df631432f3

View file

@ -2,35 +2,23 @@
// By Marc MERLIN <marc_soft@merlins.org> // By Marc MERLIN <marc_soft@merlins.org>
// Contains code (c) Adafruit, license BSD // Contains code (c) Adafruit, license BSD
#include <Adafruit_GFX.h> #include <ESP32-RGB64x32MatrixPanel-I2S-DMA.h>
RGB64x32MatrixPanel_I2S_DMA matrix;
#include "smileytongue24.h" #include "smileytongue24.h"
#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#define CLK 11 // MUST be on PORTB! (Use pin 8 on Uno)
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2
// Enable double buffering
RGBmatrixPanel *matrix = new RGBmatrixPanel(A, B, C, CLK, LAT, OE, true);
// Panel Matrix doesn't fully work like Neomatrix (which I wrote this // Panel Matrix doesn't fully work like Neomatrix (which I wrote this
// demo for), so map a few calls to be compatible. The rest comes from // demo for), so map a few calls to be compatible. The rest comes from
// Adafruit::GFX and works the same on both backends. // Adafruit::GFX and works the same on both backends.
#define setBrightness(x) fillScreen(0) // no-op, no brightness on this board #define setBrightness(x) fillScreen(0) // no-op, no brightness on this board
#define clear() fillScreen(0) #define clear() fillScreen(0)
#define show() swapBuffers(true) #define show() drawPixel(0, 0, 0); // no show method in this GFX implementation
#define Color(x,y,z) Color333(x/36,y/36,z/36) #define Color(x,y,z) color444(x/16,y/16,z/16)
// Define matrix width and height. // Define matrix width and height.
#define mw 32 #define mw 64
#define mh 16 #define mh 32
// This could also be defined as matrix->color(255,0,0) but those defines // 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() // are meant to work for Adafruit::GFX backends that are lacking color()
#define LED_BLACK 0 #define LED_BLACK 0
@ -277,17 +265,17 @@ void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, i
//Serial.print(" -> "); //Serial.print(" -> ");
//Serial.println(RGB_bmp_fixed[pixel], HEX); //Serial.println(RGB_bmp_fixed[pixel], HEX);
} }
matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h); matrix.drawRGBBitmap(x, y, RGB_bmp_fixed, w, h);
} }
// Fill the screen with multiple levels of white to gauge the quality // Fill the screen with multiple levels of white to gauge the quality
void display_four_white() { void display_four_white() {
matrix->clear(); matrix.clear();
matrix->fillRect(0,0, mw,mh, LED_WHITE_HIGH); matrix.fillRect(0,0, mw,mh, LED_WHITE_HIGH);
matrix->drawRect(1,1, mw-2,mh-2, LED_WHITE_MEDIUM); matrix.drawRect(1,1, mw-2,mh-2, LED_WHITE_MEDIUM);
matrix->drawRect(2,2, mw-4,mh-4, LED_WHITE_LOW); matrix.drawRect(2,2, mw-4,mh-4, LED_WHITE_LOW);
matrix->drawRect(3,3, mw-6,mh-6, LED_WHITE_VERYLOW); matrix.drawRect(3,3, mw-6,mh-6, LED_WHITE_VERYLOW);
matrix->show(); matrix.show();
} }
void display_bitmap(uint8_t bmp_num, uint16_t color) { void display_bitmap(uint8_t bmp_num, uint16_t color) {
@ -296,13 +284,13 @@ void display_bitmap(uint8_t bmp_num, uint16_t color) {
// Clear the space under the bitmap that will be drawn as // Clear the space under the bitmap that will be drawn as
// drawing a single color pixmap does not write over pixels // drawing a single color pixmap does not write over pixels
// that are nul, and leaves the data that was underneath // that are nul, and leaves the data that was underneath
matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK); matrix.fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK);
matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color); matrix.drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color);
bmx += 8; bmx += 8;
if (bmx >= mw) bmx = 0; if (bmx >= mw) bmx = 0;
if (!bmx) bmy += 8; if (!bmx) bmy += 8;
if (bmy >= mh) bmy = 0; if (bmy >= mh) bmy = 0;
matrix->show(); matrix.show();
} }
void display_rgbBitmap(uint8_t bmp_num) { void display_rgbBitmap(uint8_t bmp_num) {
@ -313,130 +301,131 @@ void display_rgbBitmap(uint8_t bmp_num) {
if (bmx >= mw) bmx = 0; if (bmx >= mw) bmx = 0;
if (!bmx) bmy += 8; if (!bmx) bmy += 8;
if (bmy >= mh) bmy = 0; if (bmy >= mh) bmy = 0;
matrix->show(); matrix.show();
} }
void display_lines() { void display_lines() {
matrix->clear(); matrix.clear();
// 4 levels of crossing red lines. // 4 levels of crossing red lines.
matrix->drawLine(0,mh/2-2, mw-1,2, LED_RED_VERYLOW); 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-1, mw-1,3, LED_RED_LOW);
matrix->drawLine(0,mh/2, mw-1,mh/2, LED_RED_MEDIUM); 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); matrix.drawLine(0,mh/2+1, mw-1,mh/2+1, LED_RED_HIGH);
// 4 levels of crossing green lines. // 4 levels of crossing green lines.
matrix->drawLine(mw/2-2, 0, mw/2-2, mh-1, LED_GREEN_VERYLOW); 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-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+0, 0, mw/2+0, mh-1, LED_GREEN_MEDIUM);
matrix->drawLine(mw/2+1, 0, mw/2+1, mh-1, LED_GREEN_HIGH); matrix.drawLine(mw/2+1, 0, mw/2+1, mh-1, LED_GREEN_HIGH);
// Diagonal blue line. // Diagonal blue line.
matrix->drawLine(0,0, mw-1,mh-1, LED_BLUE_HIGH); matrix.drawLine(0,0, mw-1,mh-1, LED_BLUE_HIGH);
matrix->drawLine(0,mh-1, mw-1,0, LED_ORANGE_MEDIUM); matrix.drawLine(0,mh-1, mw-1,0, LED_ORANGE_MEDIUM);
matrix->show(); matrix.show();
} }
void display_boxes() { void display_boxes() {
matrix->clear(); matrix.clear();
matrix->drawRect(0,0, mw,mh, LED_BLUE_HIGH); matrix.drawRect(0,0, mw,mh, LED_BLUE_HIGH);
matrix->drawRect(1,1, mw-2,mh-2, LED_GREEN_MEDIUM); matrix.drawRect(1,1, mw-2,mh-2, LED_GREEN_MEDIUM);
matrix->fillRect(2,2, mw-4,mh-4, LED_RED_HIGH); matrix.fillRect(2,2, mw-4,mh-4, LED_RED_HIGH);
matrix->fillRect(3,3, mw-6,mh-6, LED_ORANGE_MEDIUM); matrix.fillRect(3,3, mw-6,mh-6, LED_ORANGE_MEDIUM);
matrix->show(); matrix.show();
} }
void display_circles() { void display_circles() {
matrix->clear(); matrix.clear();
matrix->drawCircle(mw/2,mh/2, 2, LED_RED_MEDIUM); matrix.drawCircle(mw/2,mh/2, 2, LED_RED_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, LED_BLUE_HIGH);
matrix->drawCircle(mw/2+1+min(mw,mh)/8, mh/2+1+min(mw,mh)/8, min(mw,mh)/4, LED_ORANGE_MEDIUM); matrix.drawCircle(mw/2+1+min(mw,mh)/8, mh/2+1+min(mw,mh)/8, min(mw,mh)/4, LED_ORANGE_MEDIUM);
matrix->drawCircle(1,mh-2, 1, LED_GREEN_LOW); matrix.drawCircle(1,mh-2, 1, LED_GREEN_LOW);
matrix->drawCircle(mw-2,1, 1, LED_GREEN_HIGH); matrix.drawCircle(mw-2,1, 1, LED_GREEN_HIGH);
matrix->show(); matrix.show();
} }
void display_resolution() { void display_resolution() {
// not wide enough; // not wide enough;
if (mw<16) return; if (mw<16) return;
matrix->clear(); matrix.clear();
// Font is 5x7, if display is too small // Font is 5x7, if display is too small
// 8 can only display 1 char // 8 can only display 1 char
// 16 can almost display 3 chars // 16 can almost display 3 chars
// 24 can display 4 chars // 24 can display 4 chars
// 32 can display 5 chars // 32 can display 5 chars
matrix->setCursor(0, 0); matrix.setCursor(0, 0);
matrix->setTextColor(matrix->Color(255,0,0)); matrix.setTextColor(matrix.Color(255,0,0));
if (mw>10) matrix->print(mw/10); if (mw>10) matrix.print(mw/10);
matrix->setTextColor(matrix->Color(255,128,0)); matrix.setTextColor(matrix.Color(255,128,0));
matrix->print(mw % 10); matrix.print(mw % 10);
matrix->setTextColor(matrix->Color(0,255,0)); matrix.setTextColor(matrix.Color(0,255,0));
matrix->print('x'); matrix.print('x');
// not wide enough to print 5 chars, go to next line // not wide enough to print 5 chars, go to next line
if (mw<25) { if (mw<25) {
if (mh==13) matrix->setCursor(6, 7); if (mh==13) matrix.setCursor(6, 7);
else if (mh>=13) { else if (mh>=13) {
matrix->setCursor(mw-11, 8); matrix.setCursor(mw-11, 8);
} else { } else {
matrix->show(); matrix.show();
delay(2000); delay(2000);
matrix->clear(); matrix.clear();
matrix->setCursor(mw-11, 0); matrix.setCursor(mw-11, 0);
} }
} }
matrix->setTextColor(matrix->Color(0,255,128)); matrix.setTextColor(matrix.Color(0,255,128));
matrix->print(mh/10); matrix.print(mh/10);
matrix->setTextColor(matrix->Color(0,128,255)); matrix.setTextColor(matrix.Color(0,128,255));
matrix->print(mh % 10); matrix.print(mh % 10);
// enough room for a 2nd line // enough room for a 2nd line
if (mw>25 && mh >14 || mh>16) { if (mw>25 && mh >14 || mh>16) {
matrix->setCursor(0, mh-7); matrix.setCursor(0, mh-7);
matrix->setTextColor(matrix->Color(0,255,255)); matrix.setTextColor(matrix.Color(0,255,255));
if (mw>16) matrix->print('*'); if (mw>16) matrix.print('*');
matrix->setTextColor(matrix->Color(255,0,0)); matrix.setTextColor(matrix.Color(255,0,0));
matrix->print('R'); matrix.print('R');
matrix->setTextColor(matrix->Color(0,255,0)); matrix.setTextColor(matrix.Color(0,255,0));
matrix->print('G'); matrix.print('G');
matrix->setTextColor(matrix->Color(0,0,255)); matrix.setTextColor(matrix.Color(0,0,255));
matrix->print("B"); matrix.print("B");
matrix->setTextColor(matrix->Color(255,255,0)); matrix.setTextColor(matrix.Color(255,255,0));
matrix->print("*"); matrix.print("*");
} }
matrix->show(); matrix.show();
} }
void display_scrollText() { void display_scrollText() {
matrix->clear(); matrix.clear();
matrix->setTextWrap(false); // we don't wrap text so it scrolls nicely matrix.setTextWrap(false); // we don't wrap text so it scrolls nicely
matrix->setTextSize(1); matrix.setTextSize(1);
matrix->setRotation(0); matrix.setRotation(0);
for (int8_t x=7; x>=-42; x--) { for (int8_t x=7; x>=-42; x--) {
matrix->clear(); matrix.clear();
matrix->setCursor(x,0); matrix.setCursor(x,0);
matrix->setTextColor(LED_GREEN_HIGH); matrix.setTextColor(LED_GREEN_HIGH);
matrix->print("Hello"); matrix.print("Hello");
if (mh>11) { if (mh>11) {
matrix->setCursor(-20-x,mh-7); matrix.setCursor(-20-x,mh-7);
matrix->setTextColor(LED_ORANGE_HIGH); matrix.setTextColor(LED_ORANGE_HIGH);
matrix->print("World"); matrix.print("World");
} }
matrix->show(); matrix.show();
delay(50); delay(50);
} }
matrix->setRotation(3); // Rotation is broken in this implementation
matrix->setTextColor(LED_BLUE_HIGH); matrix.setRotation(3);
matrix.setTextColor(LED_BLUE_HIGH);
for (int8_t x=7; x>=-45; x--) { for (int8_t x=7; x>=-45; x--) {
matrix->clear(); matrix.clear();
matrix->setCursor(x,mw/2-4); matrix.setCursor(x,mw/2-4);
matrix->print("Rotate"); matrix.print("Rotate");
matrix->show(); matrix.show();
delay(50); delay(50);
} }
matrix->setRotation(0); matrix.setRotation(0);
matrix->setCursor(0,0); matrix.setCursor(0,0);
matrix->show(); matrix.show();
} }
// Scroll within big bitmap so that all if it becomes visible or bounce a small one. // Scroll within big bitmap so that all if it becomes visible or bounce a small one.
@ -462,12 +451,12 @@ void display_panOrBounceBitmap (uint8_t bitmapSize) {
int16_t x = xf >> 4; int16_t x = xf >> 4;
int16_t y = yf >> 4; int16_t y = yf >> 4;
matrix->clear(); matrix.clear();
// bounce 8x8 tri color smiley face around the screen // bounce 8x8 tri color smiley face around the screen
if (bitmapSize == 8) fixdrawRGBBitmap(x, y, RGB_bmp[10], 8, 8); if (bitmapSize == 8) fixdrawRGBBitmap(x, y, RGB_bmp[10], 8, 8);
// pan 24x24 pixmap // pan 24x24 pixmap
if (bitmapSize == 24) matrix->drawRGBBitmap(x, y, (const uint16_t *)bitmap24, bitmapSize, bitmapSize); if (bitmapSize == 24) matrix.drawRGBBitmap(x, y, (const uint16_t *)bitmap24, bitmapSize, bitmapSize);
matrix->show(); matrix.show();
// Only pan if the display size is smaller than the pixmap // Only pan if the display size is smaller than the pixmap
if (mw<bitmapSize) { if (mw<bitmapSize) {
@ -507,6 +496,9 @@ void display_panOrBounceBitmap (uint8_t bitmapSize) {
void loop() { void loop() {
display_four_white();
delay(3000);
// clear the screen after X bitmaps have been displayed and we // clear the screen after X bitmaps have been displayed and we
// loop back to the top left corner // loop back to the top left corner
// 8x8 => 1, 16x8 => 2, 17x9 => 6 // 8x8 => 1, 16x8 => 2, 17x9 => 6
@ -563,9 +555,6 @@ void loop() {
// If we have multiple pixmaps displayed at once, wait a bit longer on the last. // If we have multiple pixmaps displayed at once, wait a bit longer on the last.
delay(mw>8?1000:500); delay(mw>8?1000:500);
display_four_white();
delay(3000);
display_scrollText(); display_scrollText();
// pan a big pixmap // pan a big pixmap
@ -576,15 +565,15 @@ void loop() {
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
matrix->begin(); matrix.begin();
matrix->setTextWrap(false); matrix.setTextWrap(false);
matrix->setBrightness(BRIGHTNESS); matrix.setBrightness(BRIGHTNESS);
// Test full bright of all LEDs. If brightness is too high // Test full bright of all LEDs. If brightness is too high
// for your current limit (i.e. USB), decrease it. // for your current limit (i.e. USB), decrease it.
matrix->fillScreen(LED_WHITE_HIGH); matrix.fillScreen(LED_WHITE_HIGH);
matrix->show(); matrix.show();
delay(1000); delay(1000);
matrix->clear(); matrix.clear();
} }
// vim:sts=4:sw=4 // vim:sts=4:sw=4