Pages: [1] 2   Go Down
Author Topic: Arduino and 4x4 led matrix  (Read 3930 times)
0 Members and 1 Guest are viewing this topic.
Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im new to this forum and to the arduino. Ive managed to do alot of the basics, but i need help with my next learning project. the 4x4 led grid.

The leds are arranged and soldered the right way i think. I have now 4 anodes and 4 cathodes. I connect the anodes to the ardiuno trough some resistors. Where do i put the cathodes? in the digital pins? how do i program them to be "ground"? what am i missing here.

Appreciate your help.

Ole Stavne
« Last Edit: May 15, 2009, 04:53:08 pm by Amputata » Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you see this?
http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix
Easy to adapt to your 4x4.

Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks alot. I have been looking at that one, but cant quite figure out what to change and what to not. Some of the programming is hard to understand.
Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ive tried adapting the code with no success. can someone pls help me? pls post a code that works or give me some clues at least. if i connect a the positive end of a led at pin 3, and the negative lead for that led on pin 4. what whould be the code to turn it on?

sorry for my noobish question, but we have to start somewhere right? not einstein in a day.

Ole Stavne
« Last Edit: May 15, 2009, 08:16:03 pm by Amputata » Logged

United States (Texas)
Offline Offline
God Member
*****
Karma: 3
Posts: 525
Arduino socks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.arduino.cc/en/Tutorial/Blink

gotta start somewhere. the playground is a very good source for learning new things.
Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

lol. I've done all the beginner projects from the book that came with my arduino. Blink uses a led connected to ground. thats simple. Ive made a 6 led array and done the knight rider loop. but all the leds there are connected to ground.

What to do if i use a digital pin as ground?
As i said earlier. positive on pin 3 and negative on pin 4. There should be a way to turn the led on.
« Last Edit: May 16, 2009, 06:41:00 am by Amputata » Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are the 4 wires connected to the analog in pins in the picture on the site: http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
Fzzt! pop Bang!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

'As i said earlier. positive on pin 3 and negative on pin 4. There should be a way to turn the led on.'


Set pin3 to output,  pin 4 to input,  
then

digitalwrite pin3 high
digitalwrite pin4 low

the led should illuminate.
Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Doesnt work. Only when i wire the catode to ground do i get light. Using pin 3 as positive and 4 as negative doesnt work for me.

This is how far ive gotten on lighting a led this way:
Code:
int ledPin = 3;  
int ledOut = 4;

void setup()                  
{
  pinMode(ledPin, OUTPUT);      
  pinMode(ledOut, INPUT);
}

void loop()                    
{
  digitalWrite(ledPin, HIGH);  
  digitalWrite(ledOut, LOW);    
  }
« Last Edit: May 16, 2009, 07:41:56 am by Amputata » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
Fzzt! pop Bang!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

int ledPin = 3;  
int ledOut = 11;   <<<< ?

Are you using digital pins 3 & 4?

Try just the digital pins with one resistor & led connected.



Edit. Hey your post changed while I was answering  smiley
« Last Edit: May 16, 2009, 07:46:11 am by jabber » Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hehe. i saw that. i tried another pin to check if that worked, pasted the wrong code. modified now. Should be 4.
« Last Edit: May 16, 2009, 07:46:56 am by Amputata » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
Fzzt! pop Bang!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OOPS!   Both pins need to be   OUTPUTS,
 
I knew I had done this, I couldn't remember how.
Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Finally. Thanks alot. Been trying to do this for days. and it was so easy. This wont be the last time im asking noob questions here...
Logged

Sunndalsøra, Norway
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Closer and closer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ive programmed a lit more:
Code:
int ledPin1 = 3;  
int ledPin2 = 5;
int ledPin3 = 6;
int ledPin4 = 9;
int ledOut1 = 2;
int ledOut2 = 4;
int ledOut3 = 7;
int ledOut4 = 8;
int timer = 500;
void setup()                  
{
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledOut1, OUTPUT);
  pinMode(ledOut2, OUTPUT);
  pinMode(ledOut3, OUTPUT);
  pinMode(ledOut4, OUTPUT);
}

void loop()                    
{
  //første linje
  digitalWrite(ledPin4, LOW);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledOut1, LOW);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, LOW);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, LOW);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, LOW);
  delay(timer);
  
  // andre linje
  
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledOut1, LOW);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, LOW);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, LOW);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, LOW);
  delay(timer);
  
  //linje 3
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, HIGH);
  digitalWrite(ledOut1, LOW);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin3, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, LOW);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin3, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, LOW);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin3, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, LOW);
  delay(timer);
  
  //linje 4
  
  digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin4, HIGH);
  digitalWrite(ledOut1, LOW);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin4, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, LOW);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin4, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, LOW);
  digitalWrite(ledOut4, HIGH);
  delay(timer);
  digitalWrite(ledPin4, HIGH);
  digitalWrite(ledOut1, HIGH);
  digitalWrite(ledOut2, HIGH);
  digitalWrite(ledOut3, HIGH);
  digitalWrite(ledOut4, LOW);
  delay(timer);
  

  
 }

this codes runs trough all the leds turning the on and of, line for line.
THere must be a way to do this much easier with easier code. and how do i make more "led modes" with more patterns. pls post example code someone.
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Kanskje noe som dette hjelper: smiley-wink
Quote

const int TIMER = 500;
const byte NUMBER_OF_PINS = 4;
const byte NUMBER_OF_OUTS = 4;

byte ledPin[NUMBER_OF_PINS] = {3,5,6,9};
byte ledOut[NUMBER_OF_OUTS] = {2,4,7,8};

void setup(){
  //set all pins as output
  for (byte i=0; i<NUMBER_OF_PINS; i++){
      pinMode(ledPin, OUTPUT);
  }
  for (byte i=0; i<NUMBER_OF_OUTS; i++){
      pinMode(ledOut, OUTPUT);
  }
}

void loop(){
  //
  for (byte pin=0; pin<NUMBER_OF_PINS; pin++){
    digitalWrite(ledPin[pin],HIGH);
    for (byte out=0; out<NUMBER_OF_OUTS; out++){
        digitalWrite(ledOut[out],HIGH);
        delay(TIMER);
        digitalWrite(ledOut[out],LOW);
    }
    digitalWrite(ledPin[pin],LOW);
  }
}

I think this should be close to what you want to do smiley
« Last Edit: May 18, 2009, 08:03:31 pm by AlphaBeta » Logged

Pages: [1] 2   Go Up
Jump to: