## Beautiful, Running Arrow Demonstration in an 8*8 LED Matrix using Arduino Mega

by realfinetime  |  in LED Matrix at  11:58

We had already seen the circuit to connect 8*8 LED matrix to arduino through 8 bit shift register IC 74595 in previous blog. Complete the circuit as given in this page. Next is a program to make running arrows in 8*8 LED matrix. LED matrix will look like as shown in the following image.

```int latchPin = 12;  //Pin connected to ST_CP of 1st 74595
int clockPin = 13;  //Pin connected to SH_CP of 1st 74595
int dataPin = 11;   //Pin connected to DS of 1st 74595

int latchPin2 = 6;  //Pin connected to ST_CP of 2nd 74595
int clockPin2 = 7;  //Pin connected to SH_CP of 2nd 74595
int dataPin2 = 5;   //Pin connected to DS of 2nd 74595

int i=0,j=0,k=0,length_of_cathode_decimal_array;
int anode_decimal[]={1, 2, 4, 8, 16, 32, 64, 128};
int cathode_decimal[]={231, 195, 153, 60, 126, 231, 195, 153, 60, 126};

void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);

pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
}

void loop() {

int temp;
for(k=0;k<6;k++) // To give a time delay to illumination
{
/** To access individual elements of 'anode_decimal' and 'cathode_decimal' arrays **/
for(j=0;j<8;j++)
{
/************To increase the ON time of LEDs five times more than
OFF time to increase the brightness of LEDs*************/
for(i=0;i<5;i++)
{

// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, anode_decimal[j]);
// shift out the bits:
digitalWrite(latchPin, HIGH);

// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin2, LOW);
shiftOut(dataPin2, clockPin2, MSBFIRST, cathode_decimal[j]);
// shift out the bits:
digitalWrite(latchPin2, HIGH);
}

/**************************  TURN OFF ALL LEDs  ***************************/

/*** Send LOW to all Anode pins (16, 15, 11, 3, 10, 5, 6, 13) of LED matrix ***/

// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
//Send 0 0 0 0 0 0 0 0 (1) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
shiftOut(dataPin, clockPin, MSBFIRST, 0);
// shift out the bits:
digitalWrite(latchPin, HIGH);

/*** Send HIGH to all cathode pins (4, 7, 2, 8, 12, 1, 14 and 9) of LED matrix ***/

// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin2, LOW);
//Send 1 1 1 1 1 1 1 1 (255) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
shiftOut(dataPin2, clockPin2, MSBFIRST, 255);
// shift out the bits:
digitalWrite(latchPin2, HIGH);
}
}

/*** ROTATE THE 'cathode_decimal' ARRAY ONE POSITION TOWARDS LEFT SIDE *****/

// Get the length of cathode_decimal array
length_of_cathode_decimal_array = sizeof(cathode_decimal)/sizeof(cathode_decimal[0]);

// Copy the first element of array to 'temp'.
temp=cathode_decimal[0];

/**** 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;
}
```

If uploading is successful, arrows will start running on 8*8 LED matrix. Algorithm of program is clearly explained in my previous post about simple trick to design an amazing illumination in 8*8 LED matrix. Repeating the same again is not fair. Speed of running arrows can be adjusted by changing the upper limit of 'k' loop. 'j' loop is for accessing individual elements in each array. 'i' loop is for adjusting the brightness of  LEDs. 'cathode_element' array should have more than eight elements. Otherwise, 'j' loop will give an error.

1. Is there a way to make the arrows go to the right? or go the opposite direction?

Thanks

1. yeah. Just change the array values at the beginning of program.

2. for shifting arrow in opposite direction you have to change
int anode_decimal[]={1, 2, 4, 8, 16, 32, 64, 128};
to
int anode_decimal[]={128, 64, 32,16,8,4,2,1};

and it getting shifted in right direction.

2. Can i use this code ic max7219 ?

Is it also usable with Arduino UNO or should it be the Arduino Mega.
my mail: p.vanovermeire@gmail.com

Sorry if the English is not perfect, speak English but write ...

4. bedank voor het niet beantwoorden.
Zal er het mijne van denken.
Thank you for not replying. Will become of think what I also make.

## IMPORTANT NOTICE

All the circuits, published in this blog is only after testing and getting proper results in my private lab. When you try these circuits, you should check the supply voltage, polarity of components, presence of childrens nearby and shorts in the circuits. This website will not be responsible for any harm happened to you or your components caused by your carelessness.