LED Matrix using MAX7219 for Arduino

Hello guys, recently i've been working on a project that consists of making a message scroll using 3 LED matrix. I was able to find two functions online that allow me to perform this operation. Sadly, i quite dont fully understand both functions. If you take a look at the code i posted, under the fuctions section, i have two fuctions named: printCharWithShift and printStringWithShift . I need someone to explain to me how these functions work exactly. With the research ive put into it and the knowledge if gathered throughout the whole project, i was able to come up with some ideas of what some of the function statements do. You can take a look at the comments i left beside!

Thank you guys!

You haven't posted any functions or any of your code.

Neverthless, take a look at the Parola library here: LED matrix display - MD_Parola, MD_MAX72xx and MD_MAXPanel - Exhibition / Gallery - Arduino Forum

It works great with the MAX7219 and its clones

im trying to post it, sadly it exceeds the number of characters in a post..

//Required Libraries
#include <MaxMatrix.h>    // Allowing code to interact with the MAX7219
#include <avr/pgmspace.h> //PROGNEM Flash MEMORY

 
//This will be saved in the Flash MEMORY
PROGMEM const unsigned char CH[] = {
3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space ASCII (32)
1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // ! ASCII (33)
3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // " ASCII (34)
5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // # ASCII (35)
4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $ ASCII (36)
5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // % ASCII (37)
5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // & ASCII (38)
1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // ' ASCII (39)
3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // ( ASCII (40)
3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // ) ASCII (41)
5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // * ASCII (42)
5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // + ASCII (43)
2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // , ASCII (44)
4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // - ASCII (45)
2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // . ASCII (46)
4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // / ASCII (47)
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0 ASCII (48)
3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1 ASCII (49)
4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2 ASCII (50)
4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3 ASCII (51)
4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4 ASCII (52)
4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5 ASCII (53)
4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6 ASCII (54)
4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7 ASCII (55)
4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8 ASCII (56)
4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9 ASCII (57)
2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // : ASCII (58)
2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ; ASCII (59)
3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // < ASCII (60)
3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // = ASCII (61)
3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // > ASCII (62)
4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ? ASCII (63)
5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @ ASCII (64)
4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A ASCII (65)
4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B ASCII (66)
4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C ASCII (67)
4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D ASCII (68)
4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E ASCII (69)
4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F ASCII (70)
4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G ASCII (71)
4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H ASCII (72)
3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I ASCII (73)
4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J ASCII (74)
4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K ASCII (75)
4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L ASCII (76)
5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M ASCII (77)
5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N ASCII (78)
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O ASCII (79)
4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P ASCII (80)
4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q ASCII (81)
4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R ASCII (82)
4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S ASCII (83)
5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T ASCII (84)
4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U ASCII (85)
5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V ASCII (86)
5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W ASCII (87)
5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X ASCII (88)
5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y ASCII (89)
4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z ASCII (90)
2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [ ASCII (91)
4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ ASCII (92)
2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ] ASCII (93)
3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // ^ ASCII (94)
4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _ ASCII (95) 
2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // ` ASCII (96)
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a ASCII (97)
4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b ASCII (98)
4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c ASCII (99)
4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d ASCII (100)
4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e ASCII (101)
3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f ASCII (102)
4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g ASCII (103)
4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h ASCII (104)
3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i ASCII (105)
4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j ASCII (106)
4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k ASCII (107)
3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l ASCII (108)
5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m ASCII (109)
4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n ASCII (110)
4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o ASCII (111)
4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p ASCII (112)
4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q ASCII (113)
4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r ASCII (114)
4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s ASCII (115)
3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t ASCII (116)
4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u ASCII (117)
5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v ASCII (118)
5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w ASCII (119)
5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x ASCII (120)
4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y ASCII (121)
3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z ASCII (122)
3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // { ASCII (123)
1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // | ASCII (124)
3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // } ASCII (125)
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~ ASCII (126)
};

//Define the Arduino pins to talk to the MAX7219.
#define maxDataIn 8
#define maxCS 9
#define maxCLK 10

int maxInUse = 3; // How many display units in use?

MaxMatrix m(maxDataIn, maxCS, maxCLK, maxInUse); // Setting the MaxMatrix data pins to work with Arduino.

byte buffer[7]; // Holding area for our character

//-------------------------------------------------
//                    MESSAGE
//-------------------------------------------------

char message[] = "Nikki             "; //Insert Message that you want to print. 


//-------------------------------------------------
//                    SETUP
//-------------------------------------------------

void setup(){
  
//Setting the Arduinos pins as OUTPUTS in order to send the data to the MAX7219.
pinMode (maxDataIn, OUTPUT);
pinMode (maxCS, OUTPUT);
pinMode (maxCLK, OUTPUT);

//Init Matrix displays
m.init(); // Module initialize
m.clear();
m.setIntensity(0x05); // Dot matix intensity from 0 to 15
}

//-------------------------------------------------
// FUNCTIONS
//-------------------------------------------------

//This function will print the characters and shift it left.
void printCharWithShift (char character, int shiftSpeed){

if(character <32) return; // Statement will ignore any character that is outside the array.

character = character - 32;
memcpy_P(buffer, CH + 7 * character, 7); // (buffer = target, where to start copying from, number of bytes to copy.);(CH is where the array starts plus the nth character times 7 as each character occupies 7 bytes)
m.writeSprite(maxInUse8, 0, buffer); // First two bytes of buffer (and indeed the CH array) are width and height, remaining 5 are the byes to display
m.setColumn(maxInUse
8 + buffer[0], 0); // sprite = a computer graphic that may be moved on-screen and otherwise manipulated as a single entity.
// m.setColumn(col, value); * col is the index of column to be updated, range from 0 to 79. * value is the new values of LEDs, encoded as a unsigned byte.
for(int i = 0; i < buffer[0] + 1; i++){ // buffer[0] + 4 determined the space between the letters (move all the columns to the left by one column
delay(shiftSpeed);
m.shiftLeft(false, false);
}
}

//This function will print the message and shift it left.
void printStringWithShift(char *string, int shiftSpeed){

//For each character in the string, print it

while(*string != 0){
printCharWithShift(*string, shiftSpeed);
string++;
}
}

//-------------------------------------------------
// ENF OF FUNCTIONS
//-------------------------------------------------

//-------------------------------------------------
// MAIN FUNCTION THAT WILL DISPLAY MESSAGE
//-------------------------------------------------

void loop(){
printStringWithShift(message, 150); // Send message with a shiftSpeed of 20
delay(1000); // Delay before it goes on to the next loop
}

The functions load the character definitions one column at a time with a delay in between to provide the animation. Works ok but you cannot be doing anything while the scrolling is happening as it just delays.

I would suggest the Parola library as a more flexible solution for this. You can find it with my other code libraries - links in my signature block below.