Go Down

Topic: Arduino and 4x4 led matrix (Read 4360 times) previous topic - next topic

Sinwave

May 15, 2009, 11:17 pm Last Edit: May 15, 2009, 11:53 pm by Amputata Reason: 1
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

florinc


Sinwave

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.

Sinwave

#3
May 16, 2009, 03:07 am Last Edit: May 16, 2009, 03:16 am by Amputata Reason: 1
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

weirdo557

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

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

Sinwave

#5
May 16, 2009, 01:39 pm Last Edit: May 16, 2009, 01:41 pm by Amputata Reason: 1
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.

Sinwave

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


jabber

'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.

Sinwave

#8
May 16, 2009, 02:41 pm Last Edit: May 16, 2009, 02:41 pm by Amputata Reason: 1
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: [Select]

int ledPin = 3;  
int ledOut = 4;

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

void loop()                    
{
 digitalWrite(ledPin, HIGH);  
 digitalWrite(ledOut, LOW);    
 }

jabber

#9
May 16, 2009, 02:44 pm Last Edit: May 16, 2009, 02:46 pm by jabber Reason: 1
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  :)

Sinwave

#10
May 16, 2009, 02:46 pm Last Edit: May 16, 2009, 02:46 pm by Amputata Reason: 1
hehe. i saw that. i tried another pin to check if that worked, pasted the wrong code. modified now. Should be 4.

jabber

OOPS!   Both pins need to be   OUTPUTS,

I knew I had done this, I couldn't remember how.

Sinwave

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...

Sinwave

ive programmed a lit more:
Code: [Select]
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.

AlphaBeta

#14
May 19, 2009, 03:02 am Last Edit: May 19, 2009, 03:03 am by AlphaBeta Reason: 1
Kanskje noe som dette hjelper: ;)
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 :)

Go Up