Previous: Arduino Program to Turn on All LEDs of 8*8 LED Matrix
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 the 1st LED 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.
If uploading is successful, 1st LED will turn on and all other LEDs will turn off. Working of program is simple. Q0 to Q7 pins of first 74595 IC is connected to the anode pins (16, 15, 11, 3, 10, 5, 6, 13) of 8*8 LED matrix as given in the previous blog. Arduino will send 1 (0 0 0 0 0 0 0 1) to the first shift register IC. When 1 is shifted out, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of first shift register will output 0 0 0 0 0 0 0 1. Hence, 1st anode pin (16th pin) of LED matrix will get HIGH voltage. All other anode pins will get LOW voltage.
Similarly Q0 to Q7 pins of second 74595 IC is connected to the cathode pins of 8*8 LED matrix. Arduino will send 254 (1 1 1 1 1 1 1 0) to the second shift register IC. When 254 is shifted out, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of second shift register will output 1 1 1 1 1 1 1 0. Hence, 1st cathode pin (4th pin) of LED matrix will get LOW voltage. All other cathode pins will get HIGH voltage. That is, 1st LED will get HIGH voltage at anode and LOW voltage at cathode. This will turn on the 1st LED and turn off all other LEDs.
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() { /************** 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); }
If uploading is successful, 1st LED will turn on and all other LEDs will turn off. Working of program is simple. Q0 to Q7 pins of first 74595 IC is connected to the anode pins (16, 15, 11, 3, 10, 5, 6, 13) of 8*8 LED matrix as given in the previous blog. Arduino will send 1 (0 0 0 0 0 0 0 1) to the first shift register IC. When 1 is shifted out, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of first shift register will output 0 0 0 0 0 0 0 1. Hence, 1st anode pin (16th pin) of LED matrix will get HIGH voltage. All other anode pins will get LOW voltage.
Similarly Q0 to Q7 pins of second 74595 IC is connected to the cathode pins of 8*8 LED matrix. Arduino will send 254 (1 1 1 1 1 1 1 0) to the second shift register IC. When 254 is shifted out, Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of second shift register will output 1 1 1 1 1 1 1 0. Hence, 1st cathode pin (4th pin) of LED matrix will get LOW voltage. All other cathode pins will get HIGH voltage. That is, 1st LED will get HIGH voltage at anode and LOW voltage at cathode. This will turn on the 1st LED and turn off all other LEDs.
Next: Arduino program to turn on 1st and 10th LEDs |
0 comments: