8x4 Bicolor LED Matrix Question

Hello all!

I'm a newbie here but I'm picking things up at a pretty good rate. I'm working on a project that has several different functions, some of which I've already tested successfully. When I want to do something specific I research it first before buying any parts needed and that's helped save me some money. I've got the exclusive 1-of-8 part working fine, the encoder code is working, and the increment/decrement button routines are functioning perfectly, including debounce and the hold-to-speed-up feature. I'm getting pretty close to finishing the code snippets for parameter storage in EEPROM (will be replaced with FRAM later), but I'll flesh all that out once the rest of the sections are tested and working.

But ... there's one section (so far) where I'm not sure which direction to go.

What I need is an 8x4 matrix of green/red bicolor LEDs where all the LEDs are green except for one selected LED. Only the selected LED would be red, all others green. When another is selected the new LED goes red and the previously selected LED goes green. I've seen where people want to light up columns, boxes, etc., but not where all are the same color but one.

I've read posts about using shift registers and Maxim LED matrix drivers, but I'm thinking that might be overkill for what, to me at least, appears to be something fairly simple. Maybe it's not simple and I'm just being naive, I don't know, I just can't seem to work out the logic. In my simulations I can get complete rows or columns to light up but that about all. I have plenty of pins available on my Mega, even a pin for each row and column is doable (and then some).

Can anyone suggest a direction? If there's a way to do it in code that's fine, else if hardware is better I'd be fine with that too, though all the tuts I've read are based on rows, columns, smiles, frowns, etc. - no single LEDs - so I'd have to figure that out. I'd appreciate any advice.

Thanks in advance!

exclusive 1 of 8 part? They're 50 cents, readily at distributors like Digikey and Mouser.

For the matrix, depending on how it's wired, that just requires basic multiplexing, or using a MAX7219 which can control 64 LEDs with simple writes to its 8 data registers.
Hard to say without knowing more about the red/greed LEDs. 3 pin devices? 2 pin?

The one of eight reference was something I coded where only one of eight options can be selected at any one time. That's just one of the sections of code I needed to work out.

I was planning on using 2-pin LEDs - I already have a bunch of those. However, I can get and use 3-pinners if that would be better?

Thank you sir!

2 pin LEDs are harder to drive. You need something akin to a bridge to drive each led. Or two Arduino or shift register pins per led. I would go for the 3 pin type, preferably common cathode.

If you want to do this with minimum extra hardware, you could do it with 20 Arduino pins, and 4 transistors, plus some resistors. But this would mean getting the Mega to do the multiplexing, which will make the coding more difficult.

The easiest way is probably the max7219 as already suggested.

Thanks Paul. I just got done reading the datasheet for the second time and I still don't get it. Everything there seems to be about driving digits, there wasn't anything about LED arrays. Unless I'm missing something? I'll be reading it again though.

I could also go with four multiplexers and a few logic chips using six pins on the Mega. I certainly have room for a larger board, that doesn't really matter. I just thought there would be an easier way, two or three pins notwithstanding.

I assume you mean the data sheet of max7219? They are used to drive 8x8 led matrices by the million. Your 4x8 bi-colour matrix will be wired as an 8x8, electrically speaking. You will need only 3 Arduino pins, 1 resistor and 2 caps.

Does this help?
32 3-pin Red/Green common cathode LEDs.
8 groups of 4, each group has 8 anodes, 1 cathode.
MAX7219 multiplexes by driving the anodes, turning on 1 cathode.
Multiplex rate is 800 Hz, to your eye can look like anywhere from 1 to all 64 LEDs are on together.
It has 8 registers, one for each group.
Bits 0-3 will be one color, bits 4-7 will be the other color. 0b11000011 will turn on two red and two green for example. 0b11001100 will turn on two amber.
I use SPI to drive the MAX7219 when I use it.

digitalWrite (ssPin, LOW);
SPI.transfer(registerNumber); // 1 to 8
SPI.transfer(red_green_color_info); // as described above
digitalWrite (ssPin, HIGH);

Need 5 blocks like above in setup() to set scan limit register (to tell it 8 digits), intensity (brightness, 15 levels) register, normal mode (vs shutdown), no-decode mode (vs decoding to display 0-9 and HELP with seven segment displays), and display test (can be used to turn on all 64 LEDs at once).

That's a HUGE help, yes. I'm still confused (more precisely, "lost") by the codes to send to the chip. I still have a lot of learning to do, obviously. For example, if I wanted DIG3/SEGF red and all others green, what would the code be? That's the kind of thing I still have to learn. 0b11000011 doesn't help me because I don't know what it means, but this gets me started down that road.

Thank you again! At some point I will be able to help other newbies like myself. at least I hope. :slight_smile:

[EDIT]

Oh, by the way, in your image C3 is in an odd location. Was it even supposed to be there? I'm thinking not.

[/EDIT]

Ok guys, I just spent an hour trying to find something which explains this kind of command and am right back where I started. I'm going to switch off my brain for a while and try again later. If you have any suggested search parameters I can use with Google to find helpful info I'd appreciate it. I don't seem to be getting very far on my own, my feeble brain just isn't absorbing things as well as it once did, I'm afraid.

Thanks!

It's not so complex. Your 4x8 bi-colour matrix is, in effect, an 8x8 matrix where half the LEDs are red and the other half green. The max chip has 8 "registers" that the Arduino can update. These correspond to the 8 rows or columns of your matrix, depending how you wire up the LEDs. Each register contains 8 bits. Each bit controls one led in that row or column.

0b11000011 is simply a number written in binary. If the Arduino wrote that value to the 5th of the Max's 8 registers, the first, second, seventh and eighth LEDs in row or column 5 would light.

Ah, ok ... I believe I understand now. So, using CrossRoads' matrix example above, if I wanted all LEDs to be green except, say, the top-right LED (DIG6/SEGA[SEGF]), I would need to write to all eight registers as follows:

digitalWrite(ssPin, LOW);
SPI.transfer(0);
SPI.transfer(0b00001111);
SPI.transfer(1);
SPI.transfer(0b00001111);
SPI.transfer(2);
SPI.transfer(0b00001111);
SPI.transfer(3);
SPI.transfer(0b00001111);
SPI.transfer(4);
SPI.transfer(0b00001111);
SPI.transfer(5);
SPI.transfer(0b00001111);
SPI.transfer(6);
SPI.transfer(0b10000111);
SPI.transfer(7);
SPI.transfer(0b00001111);
digitalWrite(ssPin, HIGH);

Does that look to be correct? That's what I figured it should be, assuming I understood you correctly.

One last thing, does the 7219 save the last instructions in its registers/bits and display that until the next round of data? That's to say, if new data is provided, for example, to make the red LED green again and a different one red in a separate register, would I need to reissue all eight register instructions again or only the two that are being changed?

I may just be starting to understand this stuff. Still a loooong way to go though.

Thanks!

I think you need a pair of SPI.transfers for each digit:

digitalWrite(ssPin, LOW);
SPI.transfer(0);
SPI.transfer(0b00001111);
digitalWrite (ssPin, HIGH);

That's what works for me anyway.

Yes, the data stays displayed until you change it. You can do stuff and set a flag,
check the state of the flag each pass thru loop and send the data if something changed.
Or make the update a function that you call only when something has changed.

Yes, C3 is just extra paste that I missed when I created the diagram.

Thank you sir!

I just ordered a couple MAX7219 chips along with 40 3-lead bicolor LEDs from Digikey. I also ordered a few digital pots to play with. Trying to breadboard 32 LEDs is going to be fun! I'm looking forward to it.

Thanks guys for all your help! 8)