Hello arduino community today i completed the code for my 5x5 led matix. its very simple and it works its just that every time i want to display a letter i have to say show(letter, delay). If I wanted to display a 50 character long message this would be inefficient. i tried to come up with my own solution but for some reason it doesn't work and i have no idea why.
ill post the original code and the solution i tried.
Any help would be appreciated.
original code
/* Hopefully the last LED matrix code I ever make
BY: Chris Yambo
*/
int CPR = 8; // clock pin row
int DPR = 10; // data pin row
int CPC = 11; // clock pin column
int DPC = 12; // data pin column
int LP = 9; // combined the latch pins so theres only one
byte RA[] = { B10000000, B01000000, B00100000, B00010000, B00001000,}; // way to address rows individually
byte SMILEFACE[] = {B01110000, B10001000, B00000000, B01010000, B0101000};
byte SPACE[] = {B00000000, B00000000, B00000000, B00000000, B00000000};
byte A[] = {B10001000, B10001000, B11111000, B10001000, B11111000};
byte B[] = {B11111000, B10001000, B11110000, B10001000, B11111000};
byte C[] = {B11111000, B10001000, B10000000, B10001000, B11111000};
byte D[] = {B11110000, B10001000, B10001000, B10001000, B11110000};
byte E[] = {B11111000, B10000000, B11110000, B10000000, B11111000};
byte F[] = {B10000000, B10000000, B11110000, B10000000, B11111000};
byte G[] = {B11111000, B10001000, B10011000, B10000000, B11111000};
byte H[] = {B10001000, B10001000, B11111000, B10001000, B10001000};
byte I[] = {B01000000, B01000000, B01000000, B01000000, B01000000};
byte J[] = {B11111000, B10001000, B00001000, B00001000, B00001000};
byte K[] = {B10001000, B10010000, B11100000, B10010000, B10001000};
byte L[] = {B11111000, B10000000, B10000000, B10000000, B10000000};
byte M[] = {B10101000, B10101000, B10101000, B10101000, B11011000};
byte N[] = {B10001000, B10011000, B10101000, B11001000, B10001000};
byte O[] = {B11111000, B10001000, B10001000, B10001000, B11111000};
byte P[] = {B10000000, B10000000, B11111000, B10001000, B11111000};
byte Q[] = {B11111000, B10011000, B10001000, B10001000, B11111000};
byte R[] = {B10001000, B10010000, B11111000, B10001000, B11111000};
byte S[] = {B11111000, B00001000, B11111000, B10000000, B11111000};
byte T[] = {B00100000, B00100000, B00100000, B00100000, B11111000};
byte U[] = {B11111000, B10001000, B10001000, B10001000, B10001000};
byte V[] = {B00100000, B01010000, B10001000, B10001000, B10001000};
byte W[] = {B11011000, B10101000, B10101000, B10101000, B10101000};
byte X[] = {B10001000, B01010000, B00100000, B01010000, B10001000};
byte Y[] = {B11111000, B00001000, B11111000, B10001000, B10001000};
byte Z[] = {B11111000, B01000000, B00100000, B00010000, B11111000};
void setup() {
pinMode(CPR, OUTPUT);
pinMode(DPR, OUTPUT);
pinMode(CPC, OUTPUT); // setting pins as outputs
pinMode(DPC, OUTPUT);
pinMode(LP, OUTPUT);
for (int allOn = 0; allOn < 256; allOn++)
{
digitalWrite(LP, LOW);
shiftOut(DPR, CPR, LSBFIRST, allOn); // count up on rows and columns in binary
shiftOut(DPC, CPC, LSBFIRST, allOn); // cool effect to start it out every ime
digitalWrite(LP, HIGH);
delay(5);
}
if(int allOn = 255)
{
digitalWrite(LP, LOW);
shiftOut(DPR, CPR, LSBFIRST, 255); // give a second of everything on after counting sequence
shiftOut(DPC, CPC, LSBFIRST, 255); // then it's on to the main loop baby!!!
digitalWrite(LP, HIGH);
delay(1000); // wait a second of all on
}
int letter;
int row;
int timePassed; // just setting some int's in case i need them
int delayTime = 1000;
boolean pixel;
Serial.begin(9600);
}
void loop(){
show(A, 650);
show(B, 650);
show(C, 650);
show(D, 650);
show(E, 650);
show(F, 650);
show(G, 650);
show(H, 650);
show(I, 650);
show(J, 650);
show(K, 650);
show(L, 650);
show(M, 650);
show(N, 650);
show(O, 650);
show(P, 650);
show(Q, 650);
show(R, 650);
show(S, 650);
show(T, 650);
show(U, 650);
show(V, 650);
show(W, 650);
show(X, 650);
show(Y, 650);
show(Z, 650);
}
void show(byte * character, unsigned long duration){
unsigned long start = millis();
while(start + duration > millis()) //SINCE THIS WILL ALWAYS HAPPEN IT WILL ALWAYS DISPLAY THE LETTERS
{
for(int j=0; j<5; j++) // STARTS A COUT FRROM 0-4 AND MAKES IT THE INT 'J'
{
digitalWrite(LP, LOW); // PUT LATCH PIN LOW
shiftOut(DPR, CPR, LSBFIRST, RA[j]); // SHIFTT OUT ROW NUMBER 'J'
shiftOut(DPC, CPC, LSBFIRST, character[j]); //character[j]); SHIFT OUT COULMN 'J' FROM THE ARRAY OF WHATEVER CHARACTER WE CHOSE TO SHOW
digitalWrite(LP, HIGH); // PUT LATCH PIN HIGH DISPLAYING WHAT WE JUST SHIFTED
}
}
}
my solution. i'm only posting the loop here since everything else is the same
void loop(){
for(int g=0; g<4; g++)
{
byte text[] = {"test"};
byte letter[] = {text[g]};
byte test[] = {letter[0]};
show(test, 800);
}
}
void show(byte * character, unsigned long duration){
unsigned long start = millis();
while(start + duration > millis()) //SINCE THIS WILL ALWAYS HAPPEN IT WILL ALWAYS DISPLAY THE LETTERS
{
for(int j=0; j<5; j++) // STARTS A COUT FRROM 0-4 AND MAKES IT THE INT 'J'
{
digitalWrite(LP, LOW); // PUT LATCH PIN LOW
shiftOut(DPR, CPR, LSBFIRST, RA[j]); // SHIFTT OUT ROW NUMBER 'J'
shiftOut(DPC, CPC, LSBFIRST, character[j]); //character[j]); SHIFT OUT COULMN 'J' FROM THE ARRAY OF WHATEVER CHARACTER WE CHOSE TO SHOW
digitalWrite(LP, HIGH); // PUT LATCH PIN HIGH DISPLAYING WHAT WE JUST SHIFTED
}
}
}