problem understanding a code that controls an led matrix with 74hc595 ic

/*////////////////////////////////////////////////////////////////////////////////
 * Arduino code to display scrolling characters on 6 or more 8x8 LED matrix.    *
 * The no: of matrices can be increased with a small change in code.            *
 * Comments are given in each statement for editing.                            *
 * Circuit designed and program coded by Prasanth K S                           *
 * Contact : Prasanthksubash@gmail.com                                          *
/*////////////////////////////////////////////////////////////////////////////////

char msg[] ="WELCOME WIZ";//Change the text here.
int scrollspeed=5;//Set the scroll speed ( lower=faster)

int x;
int y;

//Columns
int clockPin1 = 2; //Arduino pin connected to Clock Pin 11 of 74HC595
int latchPin1 = 3; //Arduino pin connected to Latch Pin 12 of 74HC595
int dataPin1 = 4;  //Arduino pin connected to Data Pin 14 of 74HC595

//Rows
int clockPin2 = 5; //Arduino pin connected to Clock Pin 11 of 74HC595
int latchPin2 = 6; //Arduino pin connected to Latch Pin 12 of 74HC595
int dataPin2 = 7;  //Arduino pin connected to Data Pin 14 of 74HC595

//BITMAP
//Bits in this array represents one LED of the matrix
// 8 is # of rows, 6 is # of LED matrices
byte bitmap[8][7]; 

int numZones = sizeof(bitmap) / 8; // One Zone refers to one 8 x 8 Matrix ( Group of 8 columns)
int maxZoneIndex = numZones-1;
int numCols = numZones * 8;

//FONT DEFENITION
byte alphabets[][8] = {
 {0,0,0,0,0},//@ as SPACE
 //{8,28,54,99,65},//<<
 {31, 36, 68, 36, 31},//A
 {127, 73, 73, 73, 54},//B
 {62, 65, 65, 65, 34},//C
 {127, 65, 65, 34, 28},//D
 {127, 73, 73, 65, 65},//E
 {127, 72, 72, 72, 64},//F
 {62, 65, 65, 69, 38},//G
 {127, 8, 8, 8, 127},//H
 {0, 65, 127, 65, 0},//I
 {2, 1, 1, 1, 126},//J
 {127, 8, 20, 34, 65},//K
 {127, 1, 1, 1, 1},//L
 {127, 32, 16, 32, 127},//M
 {127, 32, 16, 8, 127},//N
 {62, 65, 65, 65, 62},//O
 {127, 72, 72, 72, 48},//P
 {62, 65, 69, 66, 61},//Q
 {127, 72, 76, 74, 49},//R
 {50, 73, 73, 73, 38},//S
 {64, 64, 127, 64, 64},//T
 {126, 1, 1, 1, 126},//U
 {124, 2, 1, 2, 124},//V
 {126, 1, 6, 1, 126},//W
 {99, 20, 8, 20, 99},//X
 {96, 16, 15, 16, 96},//Y
 {67, 69, 73, 81, 97},//Z
};

void setup() {
 pinMode(latchPin1, OUTPUT);
 pinMode(clockPin1, OUTPUT);
 pinMode(dataPin1, OUTPUT);

 pinMode(latchPin2, OUTPUT);
 pinMode(clockPin2, OUTPUT);
 pinMode(dataPin2, OUTPUT);
 
 //Clear bitmap
 for (int row = 0; row < 8; row++) {
   for (int zone = 0; zone <= maxZoneIndex; zone++) {
     bitmap[row][zone] = 0; 
   }
 }
}

//FUNCTIONS
// Displays bitmap array in the matrix
void RefreshDisplay()
{
 for (int row = 0; row < 8; row++) {
   int rowbit = 1 << row;
   digitalWrite(latchPin2, LOW);//Hold latchPin LOW for transmitting data
   shiftOut(dataPin2, clockPin2, MSBFIRST, rowbit);   //Transmit data

   //Start sending column bytes
   digitalWrite(latchPin1, LOW);//Hold latchPin LOW for transmitting data

   //Shift out to each matrix
   for (int zone = maxZoneIndex; zone >= 0; zone--) 
   {
     shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
   }

   //flip both latches at once to eliminate flicker
   digitalWrite(latchPin1, HIGH);//Return the latch pin 1 high to signal chip
   digitalWrite(latchPin2, HIGH);//Return the latch pin 2 high to signal chip

   //Wait
   delayMicroseconds(300);
 }
}

// Converts row and colum to bitmap bit and turn it off/on
void Plot(int col, int row, bool isOn)
{
 int zone = col / 8;
 int colBitIndex = x % 8;
 byte colBit = 1 << colBitIndex;
 if (isOn)
   bitmap[row][zone] =  bitmap[y][zone] | colBit;
 else
   bitmap[row][zone] =  bitmap[y][zone] & (~colBit);
}
// Plot each character of the message one column at a time, updated the display, shift bitmap left.
void XProcess()
{
 for (int charIndex=0; charIndex < (sizeof(msg)-1); charIndex++)
 {
   int alphabetIndex = msg[charIndex] - '@';
   if (alphabetIndex < 0) alphabetIndex=0;
   
   //Draw one character of the message
   // Each character is 5 columns wide, loop two more times to create 2 pixel space betwen characters
   for (int col = 0; col < 7; col++)
   {
     for (int row = 0; row < 8; row++)
     {
       // Set the pixel to what the alphabet say for columns 0 thru 4, but always leave columns 5 and 6 blank.
       bool isOn = 0; 
       if (col<5) isOn = bitRead( alphabets[alphabetIndex][col], 7-row ) == 1;
       Plot( numCols-1, row, isOn); //Draw on the rightmost column, the shift loop below will scroll it leftward.
     }
     for (int refreshCount=0; refreshCount < scrollspeed; refreshCount++)
       RefreshDisplay();
     //Shift the bitmap one column to left
     for (int row=0; row<8; row++)
     {
       for (int zone=0; zone < numZones; zone++)
       {
         //This right shift would show as a left scroll on display because leftmost column is represented by least significant bit of the byte.
         bitmap[row][zone] = bitmap[row][zone] >> 1;
         // Shift over lowest bit from the next zone as highest bit of this zone.
         if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7, bitRead(bitmap[row][zone+1],0));
       }
     }
   }
 }
}
void loop() {
 XProcess();
}

Hello,

so i have stumbled across this code that can display a scroling text on an led matrix matrix controled by a bunch of 74hc595 for rows and colums.

the problem is that there are no explaination of this code ,none. people that are using it on youtube also don't explain it . all they do is build the display and them give a link to the code , which apperas to be this one code all the time . I really hate coping so i wanted to undestand how thisone works so i could write my own code for the LED matrix .

now , only knowing a bit of c language i know that its going to be hard taking on arduino programing with out training ,but with all the research i've done , i know how to send data to the 74hc595 chips, i undestood the code until the part where it converts rows and columns into a bitmap . i'm completly lost there .

one of my probelms is that i can't figure out what are values of x and y in the code. i know that they have been defined in the begining of the code so they must have a purpose.

although this is not my only question i think that i can start from there and them ask more quetions.

ps: i am from Mali and studying electronics in china in chinese(first year ), this project is not a homework of any sorts , i'm not in a hurry .

any helps would be apreciated.

I'll also attach a picture of the schematic .

Capture.PNG|887x352

I cannot read the schematic on my monitor so I will take a SWAG. The main part of this is the shift register and how they work. It appears there is a group of 6 shift registers cascaded which control the columns and another shift register which controls the rows. I believe they are cascaded as a group of 7 making a total of 56 bits to send on a pass. The individual outputs of eight shift registers connect to a vertical column of LEDs. The rows are controlled by the eight transistors connected to the 8th shift register. These transistors are inverting the signal and driving the rows with more current then the shift registers can supply as it is possible to have 48 leds on at a given time while the columns are limited to 8. The leds are actually "individually addressed" on a row by row basis. Start with a piece of graph paper 48 x 8 and make a simple horizontal line maybe 1/2 the width of the matrex. Each square in the graph paper represents one led in the matrix. Each row on the graph paper is controlled with a transistor. Each column is controlled by one output from the group of 6 cascades shift registers. I cannot follow the wiring the labels are fuzzy but it appears the group of 6 shift registers is either preceded or followed with the row shift register. Since we did a row we first determine which LEDs need to be on and they become a '1' the rest a '0'. now we determine which row needs power and set that bit to a '1' the others to a zero. Then we shift out 48 bits which corresponds to a given row. All will be zero until your row is selected then shift out the pattern you constructed. Each display message is 8 row bits times 48 column bits, it then repeats for a total of 384 bits. You will have to determine which is the row and column shift registers, the best I can do is guess that the rows are in the first or last shift register. If by chance the row and column shift registers are not cascaded the logic is the same, send the columns to the group of 6 and the row to the row shift register. You would blank the LEDs while shifting and enable each row only when the data has been shifted ii and is valid. Sorry I could not read the labels on the schematic nor the part numbers, I am assuming 74HC595s, it is a good part for this. The OE would be your blanking control pin.

Don't post a screen capture.

Post the actual image. :astonished:

I trust you understand what "multiplexing" is?

The tricky bit about this particular arrangement is that what you are displaying, a row at a time, is a small piece of every character in the row, then you have to do it again for the next row. This is of course, how it has been "traditionally" done with "times square" displays until (slightly) more recently when ICs such as the MAX7219 has been available which automatically drive a matrix section (such as 8 by 8) and can be updated a column at a time.

If you actually intend to build such a display, I would definitely advise you not to try the circuit you illustrate, but use the modules now available.

|500x448 Aliexpress link