Previous: "Hello.." Display in 8*8 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. Complete the circuit as given in that page. Next is a program to display 'HAI..' in 8*8 LED matrix in a more user friendly manner. LED matrix will look like as shown in the following image. 'HAI.. ' will be displayed instead of 'HELLO...'.
Upload the following program to your arduino board.
Download program as a file from here.
If uploading is successful, 'HAI..' will start running on 8*8 LED matrix. Algorithm of program is clearly explained in my previous post about simple trick to design an amazing illumination in 8*8 LED matrix. Repeating the same again is not fair. Speed of scrolling display can be adjusted by changing the upper limit of 'k' loop given inside 'void' loop. 'j' loop inside 'void' loop is for accessing individual elements of 'anode_decimal' and 'cathode_decimal' arrays. 'i' loop inside 'void' loop is for adjusting the brightness of LEDs. 'text_to_display' array should have more than eight columns. Otherwise, 'j' loop inside 'void' loop will give an error. Read the remaining part in next page.
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, cathode_decimal_value=0; int two_multiple=1; int length_of_two_d_array=22; int anode_decimal[]={1, 2, 4, 8, 16, 32, 64, 128}; int cathode_decimal[22];
/**************** Display will be as shown below *****************/
int text_to_display[8][22]={ {1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 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);
/**************** This part of program converts the complement of
columns of 'text_to_display' 2D array to corresponding decimal and store
in 'cathode_decimal' array. In each column LSB will be top bit and MSB
will be bottom bit. 'cathode_decimal' array of 2D array will be as given
below
cathode_decimal[]={0 ,0 ,231 ,231 ,0 ,0 ,255 ,0 ,0 ,204 ,204 ,0 ,0 ,
255 ,0 ,0 ,255 ,127 ,255 ,127 ,255 ,255} *****************/
for(j=0;j<length_of_two_d_array;j++) { for(i=0;i<8;i++) { if(text_to_display[i][j]==0) { if(i>0) { for(k=0;k<i;k++) { two_multiple=two_multiple * 2; } } cathode_decimal_value=cathode_decimal_value + two_multiple; two_multiple=1; } } cathode_decimal[j]=cathode_decimal_value; cathode_decimal_value=0; }
/**********************************************************/ } void loop() { int temp; for(k=0;k<6;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 program as a file from here.
Continued in Next Page >>>> |
Sir, Which software you used to create the fonts?
ReplyDeleteThank u sir....
ReplyDelete