// 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 SCROLL 5 // 192 columns displayed on 32 column matrix make 6 pages
#define SCROLL 192
#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);
listOfFunctions(); // offload the list for a shorter setup() function
}
void loop() {
showSong();
// randomPixels();
}
void listOfFunctions() {
//********************
//** 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 showSong() { // display text residing in PROGMEM
int column = 0, row = 0, page = 0, asciiChar;
for (int k = SCROLL; k >= 0 ; k-=2) { // read banner RIGHT to LEFT "SCROLL" size steps
// for (int k = SCROLL; k >= 0 ; k--) { // read banner RIGHT to LEFT "SCROLL" size steps
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
asciiChar = pgm_read_byte_near(song + (i * 192 + j) + k ); // read 32 (chars), skip 32 (cols), repeat
// This section color the pixels according to the character read from PROGMEM
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 == '%') // green = start
led[i * COLS + j] = CRGB(63, 255, 63); // GREEN shows first column
if (asciiChar == '@') // red = stop
led[i * COLS + j] = CRGB(255, 63, 63); // RED shows last column
}
}
FastLED.show();
delay(100);
}
}
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();
}