Blogroll

Powered by Blogger.

Sunday 31 August 2014

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

by realfinetime  |  in LED Matrix at  21:04

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

0 comments:

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.

For More Electronic Tips



Blog Archive

Proudly Powered by Blogger.