## Logic Behind Turning on and Turning off Alternate LEDs in 8*8 LED Matrix (Page 2)

by realfinetime  |  in LED Matrix at  21:05

Step 3:
Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

Step 4:
In 'j' loop, j=1. Shift out 2 (anode_decimal[j]) to 1st 74595 and 170 (cathode_decimal[j]) to 2nd 74595. Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 0 1 0. Similarly, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 0 1 0 1 0 1 0. Now the LED matrix will be as shown below. This step will be done 5 times (i loop) to increase the brightness.

Step 5:
Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

Step 6:
In 'j' loop, j=2. Shift out 4 (anode_decimal[j]) to 1st 74595 and 85 (cathode_decimal[j]) to 2nd 74595. Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 1 0 0. Similarly, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 0 1 0 1 0 1 0 1. Now the LED matrix will be as shown below. This step will be done 5 times (i loop) to increase the brightness.
Step 7:
Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

Step 8:
In 'j' loop, j=3. Shift out 8 (anode_decimal[j]) to 1st 74595 and 170 (cathode_decimal[j]) to 2nd 74595. Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 1 0 0 0. Similarly, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 0 1 0 1 0 1 0. Now the LED matrix will be as shown below. This step will be done 5 times (i loop) to increase the brightness.

Step 9:
Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

'j' loop will be continued for values 4, 5 and 6.

Step 10:
In 'j' loop, j=7. Shift out 128 (anode_decimal[j]) to 1st 74595 and 170 (cathode_decimal[j]) to 2nd 74595. Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 1 0 0 0 0 0 0 0. Similarly, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 0 1 0 1 0 1 0. Now the LED matrix will be as shown below. This step will be done 5 times (i loop) to increase the brightness.
Step 11:
Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

Step 1 to Step 11 will be executed quickly and by persistence of vision, matrix will look like as shown below. We have to keep the LED matrix in this state for some time. Here comes the use of 'k' loop. For this, Step 1 to Step 11 will be executed 25 times. This will keep the LED matrix in this state for a few seconds.

Step 12:
Now, rotate the cathode_decimal[] array one position towards left. Following part of program rotate the array one position towards left.

```  // Copy the first element of 'cathode_decimal' array to 'temp'.
temp=cathode_decimal;

/**** Shift all the elements of cathode_decimal array, other than first element,
one position towards left ****/
for(i=1;i<length_of_cathode_decimal_array;i++)
{
cathode_decimal[i-1]=cathode_decimal[i];
}

/**** Copy the value in 'temp' to last position of 'cathode_decimal' array.
Then first element in old array becomes last element in new array ****/
cathode_decimal[length_of_cathode_decimal_array-1]=temp; ```

Now 'cathode_decimal' array will become:

anode_decimal[]={1, 2, 4, 8, 16, 32, 64, 128}
cathode_decimal[]={170, 85, 170, 85, 170, 85, 170, 85}

Step 13:
'j' loop will be started again. In 'j' loop, j=0. Shift out 1 (anode_decimal[j]) to 1st 74595 and 170 (cathode_decimal[j]) to 2nd 74595. Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 0 0 1. Similarly, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 0 1 0 1 0 1 0. Now the LED matrix will be as shown below. This step will be done 5 times (i loop) to increase the brightness.