//
// Two Panel NeoMatrix Hello World - This sketch will run on
// an EPS32 but not an Aruduino Uno when using 2 panels. I
// believe the 2 panels require more RAM memory than in on
// an Arduino UNO board.
//
// If you change the code to use just a single panel (see line 19
// thru 28), this sketch will run on an Uno.
//
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define PIN 2
// NeoMatrix declarations for 1 panel and 2 panel implementations
// Single panel matrix - uncomment for 1 panel implementation
/* Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800); */
// Two panel matrix - uncomment for 2 panel implementation
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, 2, 1, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE +
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
// Other declarations
const int displayWidth = matrix.width();
const char myMessage[] = "Hello World 123456";
const int myMessageCharacterCount = (sizeof(myMessage)/sizeof(myMessage[0])) - 1;
const uint16_t red = matrix.Color(255, 0, 0);
const uint16_t green = matrix.Color(0, 255, 0);
const uint16_t blue = matrix.Color(0, 0, 255);
const uint16_t yellow = matrix.Color(255, 255, 0);
const uint16_t black = matrix.Color(0, 0, 0);
const uint16_t rotatingColors[] = {red, green, blue, yellow};
const int rotatingColorsCount = (sizeof(rotatingColors)/sizeof(rotatingColors[0]));
//
// Setup function
//
void setup() {
Serial.begin(115200);
Serial.print("myMessage has ");
Serial.print(myMessageCharacterCount);
Serial.print(" characters and ");
Serial.print(rotatingColorsCount);
Serial.print(" rotating colors. Matrix panel is ");
Serial.print(displayWidth);
Serial.println(" pixels in width.");
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(255);
matrix.setTextColor(rotatingColors[0]);
}
//
// Loop function
//
int colorIterator = 0;
// Starting charPosition is the rightmost pixel on the display which is
// where the start of the first character is initially displayed.
int charPosition = displayWidth;
// restartPosition is the "virtual" position of the first character when
// the last character scrolls of the leftmost pixel of the display. This
// position assumes each character is 6 pixels wide.
int restartPosition = -((myMessageCharacterCount) * 6);
void loop() {
matrix.fillScreen(black);
matrix.setCursor(charPosition, 0);
matrix.print(myMessage);
// If last character has scrolled off of the display, change the text to
// the next color and reset the cursor position to the rightmost pixel
if (--charPosition <= restartPosition) {
if (++colorIterator >= rotatingColorsCount) colorIterator = 0;
matrix.setTextColor(rotatingColors[colorIterator]);
charPosition = displayWidth;
}
matrix.show();
delay(100);
}