Pages

Sunday 31 August 2014

Animated Demonstration of an Amazing Design in an 8*8 LED Matrix (Page 3)

<<<<  Read Previous Part

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

Step 15: 
          In 'j' loop, j=1. Shift out 2 (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 0 1 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 16: 
          Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

Step 17: 
          In 'j' loop, j=2. Shift out 4 (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 1 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 18: 
          Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

Step 19: 
          In 'j' loop, j=3. Shift out 8 (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 1 0 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 20: 
          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 21: 
          In 'j' loop, j=7. Shift out 128 (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 1 0 0 0 0 0 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 22: 
          Turn off all LEDs. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595. This will turn off all LEDs.

          Step 13 to Step 22 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 13 to Step 22 will be executed 25 times. This will keep the LED matrix in this state for a few seconds.

Step 23:
          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[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; 

Now 'cathode_decimal' array will become:

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

          That is, 'cathode_decimal' array had returned to its previous state. Now the processes will be continued again from step 1 in an infinite while loop. This will give the LED matrix illumination as shown below.

Next: Running Arrow Demonstration in 8*8 LED Matrix

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

<<<< Read the Previous Part

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[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; 

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.

Continued in Next Page >>>>

Arduino Program to Turn on Alternate LEDs of 8*8 LED Matrix (Page 1)

Previous: Running Diagonal LED Demo in LED Matrix

          We had already seen the circuit to connect 8*8 LED matrix to arduino through 8 bit shift register IC 74595 in previous blog. Next is a simple program to make an LED illumination in 8*8 LED matrix. LED matrix will look like as shown in the following image.

Now upload the following program to your arduino board.

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[]={85, 170, 85, 170, 85, 170, 85, 170};

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<25;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;      
}

Download this program as a file from here.
          Output will be an LED illumination as shown in the image. Algorithm of program is given below.

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

Step 2: 
          In 'j' loop, j=0. Don't get confused about the 'k' loop. Use of 'k' loop will be explained after some steps. Shift out 1 (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 0 0 1. 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.

Continued in Next Page  >>>>

Saturday 30 August 2014

Arduino Program to Design Running Diagonal LEDs in an 8*8 LED Matrix

Previous: Program to Turn on Diagonal LEDs of LED Matrix

          We had already seen the circuit to connect 8*8 LED matrix to arduino through 8 bit shift register IC 74595 in previous blog. Next is a simple program to make running diagonal LEDs (1, 10, 19, 28, 37, 46, 55, 64) in an 8*8 LED matrix. LED matrix will look like as shown in the following image.

Upload the following program to your arduino board.

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 j=0;
int anode_decimal[8]={1, 2, 4, 8, 16, 32, 64, 128};
int cathode_decimal[8]={254, 253, 251, 247, 239, 223, 191, 127};

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() {
    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*************/
 
      /*************************  TURN ON DIAGONAL LEDs ONLY  ***************************/  
   
      // 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);
        
      delay(100);              
            
      /**************************  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);        
   }
}


          Output will be running diagonal LEDs. We have defined two arrays in program. One is 'anode_decimal' and the other is 'cathode_decimal'. 'anode_decimal' array has numbers that should be shifted out to the anode pins of 8*8 LED matrix to turn on the diagonal LEDs only. 'cathode_decimal' array also has numbers that should be shifted out to the cathode pins of 8*8 LED matrix to turn on diagonal LEDs only.

When j=0

anode_decimal[j]=1.
cathode_decimal[j]=254.

          When anode_decimal[j] (1) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 0 0 1. When cathode_decimal[j] (254) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 1 1 1 0. This will turn on the 1st LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.

When j=1

anode_decimal[j]=2.
cathode_decimal[j]=253.

          When anode_decimal[j] (2) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 0 1 0. When cathode_decimal[j] (253) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 1 1 0 1. This will turn on the 10th LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=2

anode_decimal[j]=4.
cathode_decimal[j]=251.

          When anode_decimal[j] (4) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 1 0 0. When cathode_decimal[j] (251) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 1 0 1 1. This will turn on the 19th LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=3

anode_decimal[j]=8.
cathode_decimal[j]=247.

          When anode_decimal[j] (8) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 1 0 0 0. When cathode_decimal[j] (247) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 0 1 1 1. This will turn on the 28th LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=4

anode_decimal[j]=16.
cathode_decimal[j]=239.

          When anode_decimal[j] (16) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 1 0 0 0 0. When cathode_decimal[j] (239) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 0 1 1 1 1. This will turn on the 37th LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=5

anode_decimal[j]=32.
cathode_decimal[j]=223.

          When anode_decimal[j] (32) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 1 0 0 0 0 0. When cathode_decimal[j] (223) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 0 1 1 1 1 1. This will turn on the 46th LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=6

anode_decimal[j]=64.
cathode_decimal[j]=191.

          When anode_decimal[j] (64) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 1 0 0 0 0 0 0. When cathode_decimal[j] (191) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 0 1 1 1 1 1 1. This will turn on the 55th LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=7

anode_decimal[j]=128.
cathode_decimal[j]=127.

          When anode_decimal[j] (128) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 1 0 0 0 0 0 0 0. When cathode_decimal[j] (127) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 0 1 1 1 1 1 1 1. This will turn on the 64th LED.

Delay for 100 milliseconds.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
          Only one LED glows at a time. Each LED glows at each iteration of 'j' loop. Since iteration is very fast, due to persistence of vision, our eyes will feel that all LEDs are glowing together. Hence eye will feel that all diagonal LEDs are glowing together.

Amazing Illumination in 8*8 LED Matrix

Friday 29 August 2014

Arduino Program to Turn on Diagonal LEDs of an 8*8 LED Matrix

Previous: Program to Increase Brightness of 1st and 10th LEDs

          We have already seen the circuit to connect 8*8 LED matrix to arduino through 8 bit shift register 74595 in previous blog. Next is a simple program to turn on diagonal LEDs (1, 10, 19, 28, 37, 46, 55, 64) only and turn off all other LEDs of an 8*8 LED matrix. LED matrix will look like as shown in the following image.

Upload the following program to your arduino board.

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;
int anode_decimal[8]={1, 2, 4, 8, 16, 32, 64, 128};
int cathode_decimal[8]={254, 253, 251, 247, 239, 223, 191, 127};

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() {
    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++) 
      {  
        /*************************  TURN ON DIAGONAL LEDs ONLY  ***************************/  
   
        // 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);   
   }
}

Download this program as a file.
          If uploading is successful, diagonal LEDs will turn on and all the other LEDs will turn off as shown in the image given above. We have defined two arrays in program. One is 'anode_decimal' and the other is 'cathode_decimal'. 'anode_decimal' array has numbers that should be shifted out to the anode pins of 8*8 LED matrix to turn on diagonal LEDs only. 'cathode_decimal' array also has numbers that should be shifted out to the cathode pins of 8*8 LED matrix to turn on diagonal LEDs only.

When j=0

anode_decimal[j]=1.
cathode_decimal[j]=254.

          When anode_decimal[j] (1) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 0 0 1. When cathode_decimal[j] (254) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 1 1 1 0. This will turn on the 1st LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.

When j=1

anode_decimal[j]=2.
cathode_decimal[j]=253.

          When anode_decimal[j] (2) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 0 1 0. When cathode_decimal[j] (253) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 1 1 0 1. This will turn on the 10th LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=2

anode_decimal[j]=4.
cathode_decimal[j]=251.

          When anode_decimal[j] (4) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 0 1 0 0. When cathode_decimal[j] (251) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 1 0 1 1. This will turn on the 19th LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=3

anode_decimal[j]=8.
cathode_decimal[j]=247.

          When anode_decimal[j] (8) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 0 1 0 0 0. When cathode_decimal[j] (247) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 1 0 1 1 1. This will turn on the 28th LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=4

anode_decimal[j]=16.
cathode_decimal[j]=239.

          When anode_decimal[j] (16) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 0 1 0 0 0 0. When cathode_decimal[j] (239) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 1 0 1 1 1 1. This will turn on the 37th LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=5

anode_decimal[j]=32.
cathode_decimal[j]=223.

          When anode_decimal[j] (32) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 0 1 0 0 0 0 0. When cathode_decimal[j] (223) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 1 0 1 1 1 1 1. This will turn on the 46th LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=6

anode_decimal[j]=64.
cathode_decimal[j]=191.

          When anode_decimal[j] (64) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 0 1 0 0 0 0 0 0. When cathode_decimal[j] (191) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 1 0 1 1 1 1 1 1. This will turn on the 55th LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
When j=7

anode_decimal[j]=128.
cathode_decimal[j]=127.

          When anode_decimal[j] (128) is shifted out through 1st 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595 becomes 1 0 0 0 0 0 0 0. When cathode_decimal[j] (127) is shifted out through 2nd 74595, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595 becomes 0 1 1 1 1 1 1 1. This will turn on the 64th LED. This process continues five times ('i' loop) to increase the on time five times more than the off time. This will increase the brightness of LEDs.

Turn off all LEDs of LED matrix. For that, shift out 0 to 1st 74595 and 255 to 2nd 74595.
          Only one LED glows at a time. Each LED glows at each iteration of 'j' loop. Since iteration is very fast, due to persistence of vision, our eyes will feel that all LEDs are glowing together. Hence eye will feel that all diagonal LEDs are glowing together.

Next: Program to Make Running Diagonal Leds in LED Matrix

Arduino Program to Improve the Brightness of 1st and 10th LEDs of 8*8 Matrix

Previous: Arduino Program to Turn on 1st and 10th LEDs

          We had already seen the circuit to connect 8*8 LED matrix to arduino through 8 bit shift register IC 74595 in previous blogs. In the past blog, we found a simple program to turn on 1st and 10th LEDs only and turn off all other LEDs of an 8*8 LED matrix. But the brightness of these LEDs are very less. Here we will see a program to increase the brightness of 1st and 10th LEDs of LED matrix without modifying the circuit.


Upload the following program to your arduino board.

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;

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() {
  
    for(i=0;i<5;i++)
    {
  
      /*************************  TURN ON FIRST LED ONLY  ***************************/  
  
      /*** Send HIGH to first Anode pin (16th pin) and LOW to all 
      other anode pins (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 1 (1) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
      shiftOut(dataPin, clockPin, MSBFIRST, 1);
      // shift out the bits:    
      digitalWrite(latchPin, HIGH);


      /*** Send LOW to the first cathode pin (4th pin) and HIGH to all 
      other cathode pins (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 0 (254) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
      shiftOut(dataPin2, clockPin2, MSBFIRST, 254);
      // 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);
      
      
    for(i=0;i<5;i++)
    {  
    
      /**************************  TURN ON 10th LED ONLY  ***************************/
   
      /*** Send HIGH to second Anode pin (15th pin) and LOW to all 
      other anode pins (16, 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 1 0 (2) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
      shiftOut(dataPin, clockPin, MSBFIRST, 2);
      // shift out the bits:    
      digitalWrite(latchPin, HIGH);

      /*** Send LOW to the first cathode pin (7th pin) and HIGH to all 
      other cathode pins (4, 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 0 1 (253) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
      shiftOut(dataPin2, clockPin2, MSBFIRST, 253);
      // 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);
}

Download this program as a file.
       
          If uploading is successfull, brightness of 1st and 10th LEDs will increase. Theory of increasing brightness is very simple. In the previous program, we found that on time and off time of 1st and 10th LEDs are same. Here, using a 'for' loop, we are increasing the on time five times more than the off time. Our eyes will see the on state of LEDs five times more than the off state of LEDs. Hence by persistence of vision, our eyes will feel that LEDs are more brighter than that of previous case.

Next: Arduino Program to Turn on All Diagonal LEDs

Thursday 28 August 2014

Arduino Program to Turn on the First and Tenth LEDs of 8*8 LED Matrix

Previous: Arduino Program to Turn on the First LED

          We have already seen the circuit to connect 8*8 LED matrix to arduino through 8 bit shift register 74595 in previous blog. Next is a simple program to turn on 1st and 10th LEDs only and turn off all other LEDs of an 8*8 LED matrix. LED matrix will look like as shown in the following image.

Upload the following program to your arduino board.

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

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() {
  
    /*************************  TURN ON FIRST LED ONLY  ***************************/  
  
    /*** Send HIGH to first Anode pin (16th pin) and LOW to all 
    other anode pins (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 1 (1) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
    shiftOut(dataPin, clockPin, MSBFIRST, 1);
    // shift out the bits:    
    digitalWrite(latchPin, HIGH);


    /*** Send LOW to the first cathode pin (4th pin) and HIGH to all 
    other cathode pins (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 0 (254) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
    shiftOut(dataPin2, clockPin2, MSBFIRST, 254);
    // 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);
      
    
    /**************************  TURN ON 10th LED ONLY  ***************************/
   
    /*** Send HIGH to second Anode pin (15th pin) and LOW to all 
    other anode pins (16, 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 1 0 (2) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
    shiftOut(dataPin, clockPin, MSBFIRST, 2);
    // shift out the bits:    
    digitalWrite(latchPin, HIGH);

    /*** Send LOW to the first cathode pin (7th pin) and HIGH to all 
    other cathode pins (4, 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 0 1 (253) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
    shiftOut(dataPin2, clockPin2, MSBFIRST, 253);
    // 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);

}

          If uploading is successfull, 1st and 10th LEDs will turn on. All other LEDs will turn off. Here, LED matrix works based on the principle of persistence of vision. Arduino will turn on the 1st LED. Then turn off all LEDs. After that, arduino will turn on the 10th LED. Then turn off all LEDs. We all know that an object seen by our eyes will remain in our eyes for next 1/16th part of a second (persistence of vision). Same principle is used here. Human eye will see the glowing 1st LED. Within 1/16th part of a second, eye will see the glowing 10th LED. Only one LED glows at a time. But the eye will feel that both LEDs are glowing because of persistence of vision. Algorithm to turn on 1st and 10th LEDs together is given below.

1. Turn on 1st LED

          Arduino will shiftout number 1 (0 0 0 0 0 0 0 1) to 1st 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 0 0 0 0 0 0 0 1. After that, arduino will shiftout number 254 (1 1 1 1 1 1 1 0) to 2nd 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 1 1 1 1 1 1 1 0. This will turn on 1st LED.

2. Turn off all LEDs

          Arduino will shiftout number 0 (0 0 0 0 0 0 0 0) to 1st 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 0 0 0 0 0 0 0 0. After that, arduino will shiftout number 255 (1 1 1 1 1 1 1 1) to 2nd 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 1 1 1 1 1 1 1 1. This will turn off all LEDs.

3. Turn on 10th LED

          Arduino will shiftout number 2 (0 0 0 0 0 0 1 0) to 1st 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 0 0 0 0 0 0 1 0. After that, arduino will shiftout number 253 (1 1 1 1 1 1 0 1) to 2nd 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 1 1 1 1 1 1 0 1. This will turn on 10th LED.

4. Turn off all LEDs

          Arduino will shiftout number 0 (0 0 0 0 0 0 0 0) to 1st 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 0 0 0 0 0 0 0 0. After that, arduino will shiftout number 255 (1 1 1 1 1 1 1 1) to 2nd 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 will become 1 1 1 1 1 1 1 1. This will turn off all LEDs.

Next: Program to increase the brightness of 1st and 10th LEDs