# Theory/equation for wiring a irregularly shaped LED matrix for row/column selection

I have a large (~90) LED matrix I am whipping up. However, rather than being the traditional easy square shape, its in an odd heart shape.

The reason this is a problem, if I just use horizontal rows and vertical columns, I "waste" a lot of pins on rows/columns with only a few LEDs (like at the tip of the heart), and dont have enough pins on my current equpiment to address them all.

So the question is, how do you go about combining the LEDs such that you maintain ~10 per pin, without overlapping any rows or columns (my first attempt was simply to combine the smaller rows together, which cause them to intersect with multiple columns at a time).

I feel like this is a linear algebra problem, though I took that class 10 years ago (and failed it)...

• What matters more to you, pin count or code complexity? You could minimise both required pins and memory (for the screen buffer) at the expense of clever code. But even 90 LEDs is only 12 bytes. Mar 26, 2014 at 22:50
• Are you constrained to single side board or something? I don't see why you can't just scan the matrix as 8 x 12 or whatever is convenient. Join the anodes of the first 12 LEDs together, then the next 12, etc. join cathode of #1 to #9, # 17, #25, #33, #41, #49, #57, #65, #73, #81, #89 (and so on) Mar 26, 2014 at 22:52
• Agreed with David... you can think of the heart as just a misshapen box to save pins, but this will complicate your code quite a bit. You could also use shift registers to increase your output capability, just pay attention to the max current per pin. Mar 26, 2014 at 23:46
• I am explicitly trying to avoid shift registers and keeping it to a simple board and some resistors (for various reasons i wont go into). I dont mind code complexity, i believe its just an added layer of abstraction between pins and led patterns. I dont fully understand spehro's comment. Maybe expand more in an "answer"? Mar 26, 2014 at 23:53
• ill update the question, but with my current board i actually dont have enough pins to address everything (and do some of the other work i want), which is why i was looking to combine them. I could just order a bigger board (teensy++ will probably do it), but i just figured it was better to be clever about it. Mar 26, 2014 at 23:54

If you don't have to pack your LEDs so close together that the layout is overly constrained, simply make the schematic a rectangular 12 x 8 matrix.

Then place the LEDs physically where you want them such that they can still be interconnected with traces.

simulate this circuit – Schematic created using CircuitLab

The above two diagrams are electrically identical (a 3 x 3 matrix) but in the right hand one the LEDs are physically arranged in a crude heart shape to illustrate what the PCB layout could look like.

If your problem is how to drive a 12 x 8 matrix, that can easily be done with 20 pins, but it's not much harder to use fewer pins.. for example 3 x 74HC595 will allow the use of 10 or 11 pins with no sweat.

• This doesn't work because at its broadest, the heart will use far more pins than i can address (in the thickest section, its 13 LEDs across, and there are 12 rows total, which is too many pins for me), so a simple redistribution doesn't work. I would make a schematic... is there an online diagram generator that people use, like JSFiddle for EE? Mar 27, 2014 at 7:44
• You don't have to put the LEDs that are electrically in one row in one physical row. Click on the schematic symbol when editing your question and you can enter a schematic in Circuit Lab (do a subset for explanation, not the entire thing!) Mar 27, 2014 at 10:41
• You got the right idea there, but I already knew to rearrange the wiring while keeping the physical ones in place. The question was how do you actually figure out how to best do this (beyond winging it). Even you 9 pixel heart is fairly nontrivial, and the one i am working on is 95 pixels. Basically, what theory, rule of thumb, or technique to you apply when designing it? Mar 27, 2014 at 19:16
• The "algorithm" I used was to zig-zag down from LED1 to LEDx left top to right bottom, using the LEDs from the matrix up in the same way. That keeps all the anodes that are connected together reasonably close and mostly horizontal, and the others have to meander downward through the array. Mar 27, 2014 at 19:22