Blogroll

Powered by Blogger.

Thursday, 28 August 2014

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

by realfinetime  |  in LED Matrix at  22:19

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

2 comments:

  1. The LED matrix was originally written as a Japanese fantasy animation. Hollywood took this concept and made it into a futuristic thriller. There are dramatically choreographed fight scenes, big guns, exploding buildings and car crash scenes. God also showed each folks similar sorts of feats in our dreams. The difference is that what appeared within the film was from a Hollywood script. What appeared in our dreams was written from heaven of future violence that's encounter the world . The violence that's coming is real, but it comes with a Kingdom message of affection , redemption and restoration. it's the story of a God who will do mighty exploits on the behalf of his faithful followers.Some people could also be offended by any comparison being.visit : Cheap Essay Writing Service

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

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.