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.
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.
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 |
0 comments: