Hi All,
I’m attempting to get my new led matrix to work with my arduino. Has anyone got this particular matrix working?
I know how it works, but I’m having trouble looping through the rows. To select a row I need to set pins A, B, C and D to match the row number in binary. IE: row 1 would be D = 0, C = 0, B = 0, A = 1, row 2 would be D = 0, C = 0, B = 1, A = 0 … row 16 would have all pins set to 1. How would I do this in an elegant way? I would rather not write out this code for each row if I can help it.

digitalWrite(en,HIGH);
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(l,HIGH);
digitalWrite(l,LOW);
digitalWrite(en,LOW);

Im sure there is a super easy way to do this but I’m not experienced enough with the arduino platform to think of a way. Also would this be easier to implement if I skipped writing it in the arduino IDE and went straight to programming it in C?
Thanks
Mark

Put the row select lines on consecutive register pins, for example D4-D7. Then use the PORT command to write all the pins at once, directly, with your value. Here’s some pseudocode:

void SetRow(int row) {
PORTD = (PORTD&15) || (row<<4);
}

You’ll need to understand direct port manipulation:

http://www.arduino.cc/en/Reference/PortManipulation

but since you say “straight to programming in C” I’ll bet you’ll get it in no time.

Good luck!

Thats exactly what I’m looking for! Just one question though, I cant wrap my head around (PORTD&15) || (row<<4); Is that code supposed to actually work? Or am I right in thinking that this is a boolean statement. Either way I have an answer to my original question.
Thanks again!

I’m an idiot… The statement should have one ‘|’ for logical OR, not two for boolean.

(PORTD&15) | (row<<4).

You want to read PORTD, save the lower 4 bits (so you don’t change D0 - D3 when you’re updating D4-D7); shift row 4 bits (so it will go into D4-D7), or them together.

Chris

I kind of thought thats what you meant, but I was thinking it was some special code related to port manipulation. I didnt even think about saving the lower bits, makes sense.