// https://forum.arduino.cc/t/help-with-program-for-led-matrix-slideshow/1191399/
#include <FastLED.h>
#include <avr/pgmspace.h> // for PROGMEM
#define ROWS 16 // rows of Neopixels
#define COLS 32 // columns per row
#define NUMPIX (ROWS * COLS)
#define PAGE 5 // 192 columns displayed on 32 column matrix
#define MATRIX_PIN 2
#define MAXBRIGHT 255
CRGB led[NUMPIX];
const PROGMEM char song[] = { // sizeof() = 16 rows * 192 columns
"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" // ROW 0
"################################################################################################################################################################################################" // ROW 1
"################################################################################################################################################################################################" // ROW 2
"----------------------------------------------------------------------------------#------------#------------------------------------------------------------------------------------------------" // ROW 3
"---------------##----------------########-########-########-#--####------#------#-#------------#--------#------#-########-#--##--#-#####-----########-#------#-----------------##---------------" // ROW 4
"-----------##########------------------#--#------#--##----#--##----#------#-----#-########-----########--#-----#--------#-#--##--#-----#-----#------#-#------#-------------##########-----------" // ROW 5
"------------#-#--#-#-------------------#--#------#--##----#--#-----#-------#----#--------#------------#---#----#--------#-#--##--#-----#-----#------#--#-----#--------------#-#--#-#------------" // ROW 6
"-------------#----#--------------------#--#------#--####--#-#------#--------#--#---------#------------#----#--#---------#-#--##--#-----#-----#------#---#----#---------------#----#-------------" // ROW 7
"-------------#----#--------------------#--#------#--####--#-#------#-------#####---------#------------#---#####---------#-#--##--#-----------#------#----#---#---------------#----#-------------" // ROW 8
"------------#-#--#-#-------------------#--#------#--------#-#------#------#----#--------#------------#---#----#---------#-#--##--#-----------#------#-----#--#--------------#-#--#-#------------" // ROW 9
"-----------##########------------------#--#------#--------#-#------#-----#-----#-------#------------#---#-----#---------#-#--##--#-----------#------#------#-#-------------##########-----------" // ROW 10
"---------------##----------------------#--#------#-########-#---#### ----#------#--####---------####----#------#--------#--##--##------------########-#######------------------##---------------" // ROW 11
"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" // ROW 12
"################################################################################################################################################################################################" // ROW 13
"################################################################################################################################################################################################" // ROW 14
"%----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%" // ROW 15
};
void setup() {
FastLED.addLeds<WS2812B, MATRIX_PIN, GRB>(led, NUMPIX);
FastLED.setBrightness(MAXBRIGHT); // brightness as needed
FastLED.clear(); // clear pixel buffer
FastLED.show(); // display cleared buffer
// Serial.begin(9600);
//********************
//** TEST FUNCTIONS **
//********************
// Serial.println(strlen(song)); // number of characters in the banner
// serialSong(); // print banner (in PROGMEM) to serial monitor
// randomSeed(analogRead(A0)); // increase randomness - not needed
// fillByRowsCols();
// fillByNumber();
// showCorners(); // color corners of matrix
FastLED.show(); // last function called for pixels to be displayed
}
void loop() {
showSong();
// randomPixels();
}
void showSong() {
int column = 0, row = 0, page = 0, asciiChar;
for (int k = PAGE; k >= 0 ; k--) { // read banner RIGHT to LEFT
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
asciiChar = pgm_read_byte_near(song + (i * 192 + j) + (k * COLS)); // read 32 (chars), skip 192 (cols), repeat
if (asciiChar == '-') // white
led[i * COLS + j] = CRGB(255, 255, 255); // WHITE
if (asciiChar == '#') // blue
led[i * COLS + j] = CRGB(0, 0, 255); // BLUE
if (asciiChar == '%') // dim white
led[i * COLS + j] = CRGB(63, 63, 63); // dim white to show first and last page
}
}
FastLED.show();
delay(250);
}
}
void serialSong() { // show in serial monitor
for (int i = 0; i < strlen(song); i++) {
if (i % (strlen(song) / ROWS) == 0) // 14 rows of 189 pixels
Serial.println(); // separate the rows
int pix = pgm_read_byte_near(song + i);
Serial.write(pix);
}
}
void fillByRowsCols() {
int pix, rows, cols;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
led[i * COLS + j] = CRGB(random(2) * 255, random(2) * 255, random(2) * 255); // six primary colors
}
}
}
void fillByNumber() { // show fill order
int pix = 1; // for counting, not coloring
for (int i = 0; i < ROWS * COLS - 1; i++) {
led[i] = CRGB(random(2) * 255, random(2) * 255, random(2) * 255); // six primary colors
}
}
void showCorners() {
led[0] = CRGB(255, 000, 000); // bottom, left
led[31] = CRGB(000, 000, 255); // bottom, right
led[480] = CRGB(255, 255, 000); // top, left
led[511] = CRGB(000, 255, 000); // top, right
}
/*
15*32+0+f 15*32+31+f
led[480] led[511]
+--------------------------------+
|15 |
| |
| PROGMEM ASCII to PIXEL |
| PIX = row * COLS + col |
| |
+0_____________________________31+
led[0] led[31]
0 * 32 + 0 0 * 32 + 31
*/
void randomPixels() { // random pixel in random PRIMARY and SECONDARY color on ROWS x COLS matrix
led[random(ROWS) * random(COLS)] = CRGB((random(2) * 255), (random(2) * 255), (random(2) * 255));
FastLED.show();
}