Go Down

Topic: Scrolling LED sign (Read 1 time) previous topic - next topic

Bates

Oct 31, 2009, 10:02 pm Last Edit: Oct 31, 2009, 10:03 pm by bates.and Reason: 1
This is a prototype I made of a scrolling LED sign. This one is a 5x6 matrix of LEDs. It uses row column indexing to address each LED. All the anodes are hooked up the the rows and all the cathodes are hooked up to the columns. So if I wanted to turn the top left LED on I would set row1 high and column 1 low. I plan on making a bigger version that will hopefully be 5x80 or so using the arduino mega. The video below shows it scrolling "HELLO WORLD" http://www.youtube.com/watch?v=Rrniq8wkAPY Sorry for the poor video quality I don't have a good camera. Here's the code:
Code: [Select]

int Row1 = 2;
int Row2 = 3;
int Row3 = 4;
int Row4 = 5;
int Row5 = 6;
int Col6 = 7;
int Col5 = 8;
int Col4 = 9;
int Col3 = 10;
int Col2 = 11;
int Col1 = 12;
int Tx = 0;
int Ty = 0;
int y = 0;
int z = 0;
int WordSize = 0;
unsigned long t = 0;
//this is what defines a Letter on the most primitive letter
struct BaseLetter {
     virtual char get( byte line, byte bit ) = 0;
     virtual byte width( void ) = 0;

     static const byte NUMBER_OF_LINES = 5;
};

//Define letters of variable width using this template struct
template<byte size>
struct Letter : public BaseLetter {
     Letter( byte l0, byte l1, byte l2, byte l3, byte l4) :
           line0(l0),line1(l1),line2(l2),line3(l3),line4(l4) {
     }
     unsigned line0 : size;
     unsigned line1 : size;
     unsigned line2 : size;
     unsigned line3 : size;
     unsigned line4 : size;
     unsigned : 0;

     virtual char get( byte line, byte bit ) {
           switch (line){
                 case 0: return (line0&(1<<bit%size)?1:0); break;
                 case 1: return (line1&(1<<bit%size)?1:0); break;
                 case 2: return (line2&(1<<bit%size)?1:0); break;
                 case 3: return (line3&(1<<bit%size)?1:0); break;
                 case 4: return (line4&(1<<bit%size)?1:0); break;
           }
           return -1;
     }
     virtual byte width() { return size; }
};

/*
DEFINE THE LETTERS
*/
Letter<3> A = Letter<3>(
     B010,
     B101,
     B111,
     B101,
     B101
);
Letter<3> B = Letter<3>(
     B110,
     B101,
     B110,
     B101,
     B110
);
Letter<3> C = Letter<3>(
     B011,
     B100,
     B100,
     B100,
     B011
);
Letter<3> D = Letter<3>(
     B110,
     B101,
     B101,
     B101,
     B110
);
Letter<3> E = Letter<3>(
     B111,
     B100,
     B111,
     B100,
     B111
);
Letter<3> F = Letter<3>(
     B111,
     B100,
     B110,
     B100,
     B100
);
Letter<5> G = Letter<5>(
     B01110,
     B10000,
     B10011,
     B10001,
     B01110
);
Letter<3> H = Letter<3>(
     B101,
     B101,
     B111,
     B101,
     B101
);
Letter<3> I = Letter<3>(
     B111,
     B010,
     B010,
     B010,
     B111
);
Letter<3> J = Letter<3>(
     B011,
     B001,
     B001,
     B101,
     B010
);
Letter<4> K = Letter<4>(
     B1001,
     B1010,
     B1100,
     B1010,
     B1001
);
Letter<3> L = Letter<3>(
     B100,
     B100,
     B100,
     B100,
     B111
);
Letter<5> M = Letter<5>(
     B10001,
     B11011,
     B10101,
     B10001,
     B10001
);
Letter<5> N = Letter<5>(
     B10001,
     B11001,
     B10101,
     B10011,
     B10001
);
Letter<3> O = Letter<3>(
     B010,
     B101,
     B101,
     B101,
     B010
);
Letter<3> P = Letter<3>(
     B110,
     B101,
     B110,
     B100,
     B100
);
Letter<5> Q = Letter<5>(
     B01110,
     B10001,
     B10101,
     B10011,
     B01100
);
Letter<4> R = Letter<4>(
     B1110,
     B1010,
     B1100,
     B1010,
     B1001
);
Letter<3> S = Letter<3>(
     B011,
     B100,
     B010,
     B001,
     B110
);
Letter<3> T = Letter<3>(
     B111,
     B010,
     B010,
     B010,
     B010
);
Letter<3> U = Letter<3>(
     B101,
     B101,
     B101,
     B101,
     B010
);
Letter<5> V = Letter<5>(
     B10001,
     B10001,
     B10001,
     B01010,
     B00100
);
Letter<5> W = Letter<5>(
     B10001,
     B10001,
     B10001,
     B10101,
     B01010
);
Letter<3> X = Letter<3>(
     B101,
     B101,
     B010,
     B101,
     B101
);
Letter<3> Y = Letter<3>(
     B101,
     B101,
     B010,
     B010,
     B010
);
Letter<3> Z = Letter<3>(
     B111,
     B001,
     B010,
     B100,
     B111
);
Letter<1> Ls = Letter<1>(
     B0,
     B0,
     B0,
     B0,
     B0
);
Letter<2> Ws = Letter<2>(
     B00,
     B00,
     B00,
     B00,
     B00
);

/*
DEFINE THE WORD
*/
const byte WORD_LENGTH = 19;//MAX is around 26
BaseLetter* word1[WORD_LENGTH] = {&H, &Ls, &E, &Ls, &L, &Ls, &L, &Ls, &O, &Ws, &W, &Ls, &O, &Ls, &R, &Ls, &L, &Ls, &D}; //Hello world
//BaseLetter* word1[WORD_LENGTH] = {&T, &Ls, &H, &Ls, &X, &Ws, &A, &Ls, &L, &Ls, &P, &Ls, &H, &Ls, &A, &Ls, &B, &Ls, &E, &Ls, &T, &Ls, &A}; //thx Alphabeta
char Text[5][5*(WORD_LENGTH/2)+(WORD_LENGTH/2)];


void setup() {
 pinMode(Row1, OUTPUT);//Row1
 pinMode(Row2, OUTPUT);//Row2
 pinMode(Row3, OUTPUT);//Row3
 pinMode(Row4, OUTPUT);//Row4
 pinMode(Row5, OUTPUT);//Row5
 pinMode(Col6, OUTPUT);//Col6
 pinMode(Col5, OUTPUT);//Col5
 pinMode(Col4, OUTPUT);//Col4
 pinMode(Col3, OUTPUT);//Col3
 pinMode(Col2, OUTPUT);//Col2
 pinMode(Col1, OUTPUT);//Col1
 Serial.begin(9600);
 
 for(int i=0; i<WORD_LENGTH; i++){
   WordSize = WordSize + (word1[i]->width());
 }

 for(Ty=0;Ty<(5*(WORD_LENGTH/2)+(WORD_LENGTH/2));Ty++){
    for(Tx=0;Tx<=5;Tx++){
      Text[Tx][Ty]=0;
    }
  }
  Tx=0;
  Ty=0;
  for (int wordIndex=0; wordIndex<WORD_LENGTH; wordIndex++){
           //loop through all the columns
       for (int bit=(word1[wordIndex]->width()-1); bit>=0; bit--){
                 //loop through all the rows
           for (int line=0; line<BaseLetter::NUMBER_OF_LINES; line++){
                    //print the value at the current letter, at the current line at the current bit
                    //Serial.print(word1[wordIndex]->get(line,bit),DEC);
                          Text[Tx][Ty]=int(word1[wordIndex]->get(line,bit));
                          Tx++;
                          //Serial.print(Text[Tx][Ty],DEC);
                 }
                 //Serial.println();
                       Tx=0;
                       Ty++;
           }
     }
       Tx = 0;
       Ty = 0;
       for(Tx=0;Tx<5;Tx++){
         for(Ty=0;Ty<(5*(WORD_LENGTH/2)+(WORD_LENGTH/2));Ty++){
           Serial.print(Text[Tx][Ty],DEC);
         }
         Serial.println();
       }
}

void loop() {
  Tx = 0;
  Ty = 0;

 for(y=0; y <6; y++){
   if(t<100){
     t++;}
   else{
     z++;
     t=0;}
   if(z==((5*(WORD_LENGTH/2)+(WORD_LENGTH/2))-6))
   {z=0;}
   digitalWrite(Row1, Text[0][y+z]);
   digitalWrite(Row2, Text[1][y+z]);
   digitalWrite(Row3, Text[2][y+z]);
   digitalWrite(Row4, Text[3][y+z]);
   digitalWrite(Row5, Text[4][y+z]);
   //delay(1000);
   if(y==0){
     pinMode(Col1,OUTPUT);
     digitalWrite(Col1, LOW);
     pinMode(Col2,INPUT);
     pinMode(Col3,INPUT);
     pinMode(Col4,INPUT);
     pinMode(Col5,INPUT);
     pinMode(Col6,INPUT);}

   if(y==1){
     //Serial.println("Col2");
     pinMode(Col2,OUTPUT);
     pinMode(Col1,INPUT);
     digitalWrite(Col2, LOW);
     pinMode(Col3,INPUT);
     pinMode(Col4,INPUT);
     pinMode(Col5,INPUT);
     pinMode(Col6,INPUT);}
   if(y==2){
     pinMode(Col3,OUTPUT);
     pinMode(Col1,INPUT);
     pinMode(Col2,INPUT);
     digitalWrite(Col3, LOW);
     pinMode(Col4,INPUT);
     pinMode(Col5,INPUT);
     pinMode(Col6,INPUT);}
   if(y==3){
     pinMode(Col4,OUTPUT);
     pinMode(Col1,INPUT);
     pinMode(Col2,INPUT);
     pinMode(Col3,INPUT);
     digitalWrite(Col4, LOW);
     pinMode(Col5,INPUT);
     pinMode(Col6,INPUT);}
   if(y==4){
     pinMode(Col5,OUTPUT);
     pinMode(Col1,INPUT);
     pinMode(Col2,INPUT);
     pinMode(Col3,INPUT);
     pinMode(Col4,INPUT);
     digitalWrite(Col5, LOW);
     pinMode(Col6,INPUT);}
   if(y==5){
     pinMode(Col6,OUTPUT);
     pinMode(Col1,INPUT);
     pinMode(Col2,INPUT);
     pinMode(Col3,INPUT);
     pinMode(Col4,INPUT);
     pinMode(Col5,INPUT);
     digitalWrite(Col6, LOW);}
   delay(1);
 }
 y=0;

}



I want to thank AlphaBeta and the others who helped me get this code working. Now I just need to solve my memory problems, I can only have about 26 characters at a time right now because I run out of RAM.

mowcius

I like it!   ;)

Your code is also good because it is simple and does things logically. A great piece of code for beginners as well as code techies!

I would personally use a smaller LED matrix (i presume that was just LEDs) but it looks good.

Any idea of what you are going to do with it?

Mowcius

Bates

#2
Nov 02, 2009, 03:17 am Last Edit: Nov 02, 2009, 03:19 am by bates.and Reason: 1
I had a lot of help with some of the code but thanks.

By smaller matrix do you mean less space between the LEDs? I want to expand this to get real big in the hope that I can make it visible from very far away. This is mostly just something I want to do so I have it. Not sure exactly what it will be used for.

mowcius

Quote
I had a lot of help with some of the code but thanks.

Yeah but there aren't many people on these forums who can get perfect code without some help...

Quote
By smaller matrix do you mean less space between the LEDs?

Yes, that's what I meant
Quote
I want to expand this to get real big in the hope that I can make it visible from very far away.

Ok sounds good, you would then need some more powerful LEDs and some beefy transistors to power it

Quote
This is mostly just something I want to do so I have it. Not sure exactly what it will be used for.

That's a problem I seem to have a lot, make something cos you want to make it but have no reason for making it...

Mowcius

fruitkid101

Hi I've a question. I'm new to arduino and have only done simple things with LED matrixes (ie, scrolling lines). I downloaded the code and everthing and it all works. How can I change the words? Help?

justjoe

You can change the code in this area:

/*
DEFINE THE WORD
*/
const byte WORD_LENGTH = 19;//MAX is around 26
BaseLetter* word1[WORD_LENGTH] = {&H, &Ls, &E, &Ls, &L, &Ls, &L, &Ls, &O, &Ws, &W, &Ls, &O, &Ls, &R, &Ls, &L, &Ls, &D}; //Hello world
//BaseLetter* word1[WORD_LENGTH] = {&T, &Ls, &H, &Ls, &X, &Ws, &A, &Ls, &L, &Ls, &P, &Ls, &H, &Ls, &A, &Ls, &B, &Ls, &E, &Ls, &T, &Ls, &A}; //thx Alphabeta
char Text[5][5*(WORD_LENGTH/2)+(WORD_LENGTH/2)];

 

fruitkid101

Thanks, I knew that. But how would I actually change the words? The letters in that segment of code are all jumbled up.

justjoe


Th &hs starts the word. &Ls and &Ws are in between the letters.

BaseLetter* word1[WORD_LENGTH] = {&H, &Ls, &E, &Ls, &L, &Ls, &L, &Ls, &O, &Ws, &W, &Ls, &O, &Ls, &R, &Ls, &L, &Ls, &D}; //Hello world


After typing your message count all the letters including the &Ls and the &Ws to put in here:

const byte WORD_LENGTH = 19;//MAX is around 26

justjoe

Sorry...

The &h, starts...

fruitkid101

hahaha. Time to start deciphering!

Go Up