Pages: [1]   Go Down
Author Topic: 384 Led's!  (Read 671 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okay i bought 6 8x8 led matrix's on ebay and i have managed to wire one up using 16 pins, lmao on my arduino, how would i go about wiring all of them to create some sort of display, I am awaiting on 10 shift registers, i am confused about the code?
 
currently I am using the code shown below to do a simple animation. I need help like scrolling messages and stuff i want to make it 16 by 24? any advice?!?!?! questions?

yes my code works theres no problems but i need to understand how to use the shift registers which i am lost, i  have used them before, using the examples included in arduino0020, but woudl it be 2 shift registers per matrix?
 :o


Code:
int pin1 = 2;
int pin2 = 3;
int pin3 = 4;
int pin4 = 5;
int pin5 = 6;
int pin6 = 7;
int pin7 = 8;
int pin8 = 9;

int pin9 = 22;
int pin10 = 24;
int pin11 = 26;
int pin12 = 28;
int pin13 = 30;
int pin14 = 32;
int pin15 = 34;
int pin16 = 36;

void setup(){
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
  pinMode(pin4, OUTPUT);
  pinMode(pin5, OUTPUT);
  pinMode(pin6, OUTPUT);
  pinMode(pin7, OUTPUT);
  pinMode(pin8, OUTPUT);

  pinMode(pin9, OUTPUT);
  pinMode(pin10, OUTPUT);
  pinMode(pin11, OUTPUT);
  pinMode(pin12, OUTPUT);
  pinMode(pin13, OUTPUT);
  pinMode(pin14, OUTPUT);
  pinMode(pin15, OUTPUT);
  pinMode(pin16, OUTPUT);

}

void loop(){
led_1();
}


void led_1(){
  digitalWrite(pin1,  HIGH);  // 1
  digitalWrite(pin6,  LOW);  // 2
  digitalWrite(pin16, LOW);  // 3
  digitalWrite(pin4,  LOW);  // 4
  digitalWrite(pin9,  LOW);  // 5
  digitalWrite(pin15, LOW);  // 6
  digitalWrite(pin10, LOW);  // 7
  digitalWrite(pin13, HIGH);  // 8
  
  digitalWrite(pin5,  LOW);  // 1
  digitalWrite(pin11, HIGH); // 2
  digitalWrite(pin12, HIGH); // 3
  digitalWrite(pin2,  HIGH);  // 4
  digitalWrite(pin14, HIGH); // 5
  digitalWrite(pin3,  HIGH);  // 6
  digitalWrite(pin7,  HIGH);  // 7
  digitalWrite(pin8,  LOW);  // 8

delay(200);

  digitalWrite(pin1,  LOW);  // 1
  digitalWrite(pin6,  HIGH);  // 2
  digitalWrite(pin16, LOW);  // 3
  digitalWrite(pin4,  LOW);  // 4
  digitalWrite(pin9,  LOW);  // 5
  digitalWrite(pin15, LOW);  // 6
  digitalWrite(pin10, HIGH);  // 7
  digitalWrite(pin13, LOW);  // 8
  
  digitalWrite(pin5,  HIGH);  // 1
  digitalWrite(pin11, LOW); // 2
  digitalWrite(pin12, HIGH); // 3
  digitalWrite(pin2,  HIGH);  // 4
  digitalWrite(pin14, HIGH); // 5
  digitalWrite(pin3,  HIGH);  // 6
  digitalWrite(pin7,  LOW);  // 7
  digitalWrite(pin8,  HIGH);  // 8
  
delay(200);

  digitalWrite(pin1,  LOW);  // 1
  digitalWrite(pin6,  LOW);  // 2
  digitalWrite(pin16, HIGH);  // 3
  digitalWrite(pin4,  LOW);  // 4
  digitalWrite(pin9,  LOW);  // 5
  digitalWrite(pin15, HIGH);  // 6
  digitalWrite(pin10, LOW);  // 7
  digitalWrite(pin13, LOW);  // 8
  
  digitalWrite(pin5,  HIGH);  // 1
  digitalWrite(pin11, HIGH); // 2
  digitalWrite(pin12, LOW); // 3
  digitalWrite(pin2,  HIGH);  // 4
  digitalWrite(pin14, HIGH); // 5
  digitalWrite(pin3,  LOW);  // 6
  digitalWrite(pin7,  HIGH);  // 7
  digitalWrite(pin8,  HIGH);  // 8
  
  delay(200);

  digitalWrite(pin1,  LOW);  // row 1
  digitalWrite(pin6,  LOW);  // 2
  digitalWrite(pin16, LOW);  // 3
  digitalWrite(pin4,  HIGH);  // 4
  digitalWrite(pin9,  HIGH);  // 5
  digitalWrite(pin15, LOW);  // 6
  digitalWrite(pin10, LOW);  // 7
  digitalWrite(pin13, LOW);  // 8
  
  digitalWrite(pin5,  HIGH);  // col 1
  digitalWrite(pin11, HIGH); // 2
  digitalWrite(pin12, HIGH); // 3
  digitalWrite(pin2,  LOW);  // 4
  digitalWrite(pin14, LOW); // 5
  digitalWrite(pin3,  HIGH);  // 6
  digitalWrite(pin7,  HIGH);  // 7
  digitalWrite(pin8,  HIGH);  // 8
  
delay(200);

  digitalWrite(pin1,  LOW);  // row 1
  digitalWrite(pin6,  LOW);  // 2
  digitalWrite(pin16, HIGH);  // 3
  digitalWrite(pin4,  HIGH);  // 4
  digitalWrite(pin9,  HIGH);  // 5
  digitalWrite(pin15, HIGH);  // 6
  digitalWrite(pin10, LOW);  // 7
  digitalWrite(pin13, LOW);  // 8
  
  digitalWrite(pin5,  HIGH);  // col 1
  digitalWrite(pin11, HIGH); // 2
  digitalWrite(pin12, LOW); // 3
  digitalWrite(pin2,  LOW);  // 4
  digitalWrite(pin14, LOW); // 5
  digitalWrite(pin3,  LOW);  // 6
  digitalWrite(pin7,  HIGH);  // 7
  digitalWrite(pin8,  HIGH);  // 8
  
delay(200);

  digitalWrite(pin1,  LOW);  // row 1
  digitalWrite(pin6,  HIGH);  // 2
  digitalWrite(pin16, HIGH);  // 3
  digitalWrite(pin4,  HIGH);  // 4
  digitalWrite(pin9,  HIGH);  // 5
  digitalWrite(pin15, HIGH);  // 6
  digitalWrite(pin10, HIGH);  // 7
  digitalWrite(pin13, LOW);  // 8
  
  digitalWrite(pin5,  HIGH);  // col 1
  digitalWrite(pin11, LOW); // 2
  digitalWrite(pin12, LOW); // 3
  digitalWrite(pin2,  LOW);  // 4
  digitalWrite(pin14, LOW); // 5
  digitalWrite(pin3,  LOW);  // 6
  digitalWrite(pin7,  LOW);  // 7
  digitalWrite(pin8,  HIGH);  // 8
  
delay(200);

  digitalWrite(pin1,  HIGH);  // row 1
  digitalWrite(pin6,  HIGH);  // 2
  digitalWrite(pin16, HIGH);  // 3
  digitalWrite(pin4,  HIGH);  // 4
  digitalWrite(pin9,  HIGH);  // 5
  digitalWrite(pin15, HIGH);  // 6
  digitalWrite(pin10, HIGH);  // 7
  digitalWrite(pin13, HIGH);  // 8
  
  digitalWrite(pin5,  LOW);  // col 1
  digitalWrite(pin11, LOW); // 2
  digitalWrite(pin12, LOW); // 3
  digitalWrite(pin2,  LOW);  // 4
  digitalWrite(pin14, LOW); // 5
  digitalWrite(pin3,  LOW);  // 6
  digitalWrite(pin7,  LOW);  // 7
  digitalWrite(pin8,  LOW);  // 8
  
delay(200);

  digitalWrite(pin1,  HIGH);  // row 1
  digitalWrite(pin6,  HIGH);  // 2
  digitalWrite(pin16, HIGH);  // 3
  digitalWrite(pin4,  HIGH);  // 4
  digitalWrite(pin9,  HIGH);  // 5
  digitalWrite(pin15, HIGH);  // 6
  digitalWrite(pin10, HIGH);  // 7
  digitalWrite(pin13, HIGH);  // 8
  
  digitalWrite(pin5,  LOW);  // col 1
  digitalWrite(pin11, LOW); // 2
  digitalWrite(pin12, LOW); // 3
  digitalWrite(pin2,  LOW);  // 4
  digitalWrite(pin14, LOW); // 5
  digitalWrite(pin3,  LOW);  // 6
  digitalWrite(pin7,  LOW);  // 7
  digitalWrite(pin8,  LOW);  // 8
  
delay(200);
}
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1214
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice code for a ProofOfConcept. What shows up when you run it? I cant quite work out how setting the 16 lines maps to what LEDs light up in the Matrix...
Scrolling a 10 character would thus require you to write thet code 100s of times, very carefully choosing each LED ...  
You need to modularize and make layers of abstraction.

First step is to change your pin names to a functional name, not its position in the electroincs, just to avoid confusion. You write
"pin16" is the 36th pin on the Arduino, and then in the coe the comment line says this is row 3; .. so call it that: int row3 = 36 ; BTW, I prefer to use a byte when the number is that small: byte row3 = 36 ;

We'll move the row and column lists into a (read only) array:
Code:
byte col[] = { 2, 7, 16 ... } //  giving the 8 Arduino pin nos that map to displayed orer of columns
byte row[] = { 6, 26 ... } ; // ditto rows
The initialization now greatly simplifies to:
Code:
for (int L = 0 ; L<8 ; L++ ) {
  pinMode(row[L],OUTPUT) ; pinMode(col[L],OUTPUT) ;
  }

So now we need an array that holds the image of what you want to scroll. Each code line is a vertical column, ie the row data for one column
Code:
byte img[][] = { { 1, 0, 0, 0, 0, 0, 0, 1 },
             { 0, 1, 0, 0, 0, 0, 1, 0 },
             { ... }  // just as many columns as you want to
             } ;
The magic is in your main code you have 3 nested loops. The outer most loop contains the scroll delay() and a counter T.

The middle loop counts from 0 to 7 in variable C and is the destination column. As I do not know how you matrix works, I presume I have to turn on one column (and all others off) and a little later go to the next column (POV effect)

The inner most loop counts from 0 to 7 in variable R and uses the 0/1 info to produce a digitalWrite ON or OFF.
Code:
// middle loop
  for (int C=0;C<7;C++) {
    for (int S=0;S<8;S++) digitalWrite(col[S],LOW) ; // quick clear of all columns
//innermost loop
     for (int R=0;R<8;R++)
       digitalWrite(col[C],(img[C+T][R])?HIGH:LOW) ;
OK, that scrolls nicely in a single display.

SHift regsiters .. hmm... well, to early to tell, as I cant second guess too much how you need to connect them. Basically though I think instead of using 8 colum lines (to take an example), you use 3 lines. The digitalWrite statement int the innner loop above becomes something like
Code:
digitalWrite(Serilapin,(img[C+T][R])?HIGH:LOW) ;
digitalWrite(clockpin,HIGH);digitalWrite(Clockpin,LOW);
and in the middle loop you toggle the latch. In the middle loop you let a single HIGH bit shift down the column shitregisters.

Yes, above is just hints and snippets. I suspect the final result will be a hundered lines of code or two. But who said it should be easy?!

BTW, I have not syntax checked this code, I just wrote it straight in the forum editor, so it may need a little correction. But you should be able to get the principles of the loop/array stuff.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well when i run it the four corners light up then they turn off and 4 inner corners and then they turn off and 4 more inner corners turn on then once the center lights up like if they "crashed" the center expands outward and at the end all of them are on and just repeats...


what do you mean in this line?

""BTW, I prefer to use a byte when the number is that small: byte row3 = 36 ;""


what do you also mean moving them onto an array?
- sorry real beginner lol only been messing with arduinos for about 3-4 weeks at most,

BTW,

i have been trying to understand how to use

""for""
Code:
for (int L = 0 ; L<8 ; L++ ) {
  pinMode(row[L],OUTPUT) ; pinMode(col[L],OUTPUT) ;
  }

can you explain that please? or where can i read about how to use it. i tried to understand it under "reference" but i cant =\

my matrix works that i turn on the row (set to high) and have to subsequently turn ON (set to high) the column its weird
Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 659
Arduino sucks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i have been trying to understand how to use

""for""
Code:

for (int L = 0 ; L<8 ; L++ ) {
  pinMode(row[L],OUTPUT) ; pinMode(col[L],OUTPUT) ;
  }




can you explain that please? or where can i read about how to use it. i tried to understand it under "reference" but i cant =\

"As long as integer L, which starts as "0", is smaller than 8, increment (++) L by one, doing the following"

Now you can see, that it does set the pinMode for the Led column and row "L" in one batch, as opposed to writing every one down manually, which are 16 lines of codes just to map simple outputs.
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1214
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What do you mean in this line?
""BTW, I prefer to use a byte
I am so measly with my RAM memory. A pin number is between 0 and 50+. An int can store a number up to 65000+, a byte only 256. So by using byte for the pin number instead of int, I save a byte in RAM. That is 16 bytes for your 16 variables.

Quote
moving them onto an array
means: Instead of using an indvidual variable for each pin, use an array for them all. (Check array in the reference) I thought the initialisation example shows the "power of array". The for loop will call the two pinMode commands one for each number in the array (1st number, 2nd number ...) as indexed by the variable L.

Put another way - I'll try and show what happens
When we execute the for (int L = 0 ; L<8 ; L++ ), the int L=0 does two things (very terse code this, sorry) It creates the variable L which will disappear again when the for loops end, and it sets it to the value 0. Then the code between the { } gets executed

pinMode(row[L],OUTPUT) is "translated" as pinMode(6,OUTPUT). Why, because row[L] says row[0] (the L is 0 at this time) which means the first number we deined in the row array - in this case the 6 (the code above). Ditto the second, which sets pin 2.

When we reach the "}" the for loop does the L<8 part, which checks if we want to "go round one more time". We do, as L is less than 8. the for loop then does the 3rd part L++, incrementing L (so it now contains 1) We then execute the for body again.

This time pinMode(row[L],OUTPUT) is "translated" as pinMode(26,OUTPUT) as we're looking at the 2nd number in the row array. (Yes, C arrays start at 0)

Experiment a little with that concept, you learn more from that then me typing  smiley  Put in some Serial.print(L) and Serial.print(row[L]) and you'll get the idea.

The Arduino is great, but it requires knowledge in 2 fields - some electronics AND some C programming. On the other hand, in a "simple & safe" setup like a LED matrix you can try lots of things without blowing anything up. The electroincs is reasonably robust and reprogramming is simple. Try, try and try again
« Last Edit: October 08, 2010, 07:29:42 pm by 3dprinter » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i was looking at array on the reference page and i am confused with this line
Code:
Finally you can both initialize and size your array, as in mySensVals. Note that when declaring an array of type char, one more element than your initialization is required, to hold the required null character.

does that mean  i would create one like for when using a button?

int newByte=0; ?

Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1214
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That paragraph is confusing; the two sentences belong to different examples:
Quote
Finally you can both initialize and size your array, as in mySensVals
is clear enough, mySenseVals is declared as an 6 integers array (numbered from 0 thru 5) and then only the first 5 are initialized.

Quote
Note that when declaring an array of type char, one more element than your initialization is required, to hold the required null character.
really is a comment on the char message[6]example. A string is a bit between a pair of "-marks and is effectivly an array of characters (a char is a single letter in '-marks) and should/must end with a NULL character (written as \0) The comment just points out that if you size the array you remember to include this char in your count.

I am unable to understand what you mean to ask with
Quote
does that mean  i would create one like for when using a button?
int newByte=0; ?
Logged

Pages: [1]   Go Up
Jump to: