How many I/Os are needed to drive electronic dice?

I recently bought a very low cost electronic dice kit on an impulse. Assembling it was good retro-fun for a while. The circuit design is was purely 70ies style: A CD4017, a NE555 and a couple of transistors. Of course, this got me thinking: How would it be done today in a most efficient way? Of course this means using a microcontroller, and, of course this means using as few resources as possible. Will an ATiny10 with 3 I/Os pins do?

The dice pattern consists of 7 LEDs. However, one will quickly notice that 6 of these LEDs only light up in pairs, so that only 3 pairs LEDs plus the middle one need to be controlled. This requires four I/Os – still too much!

One obvious approach to reducing the number of I/Os is to use charlieplexing. There are plenty of charlieplexed electronic dice on the web. Charliplexing allows to control n²-n LEDs with n I/O lines. Therefore only three I/O lines are needed with charliplexing. Almost there, but still a bit too much for the ATtiny10, since an additional I/O is needed to initiate the “die roll”.

Charlieplexing uses the tri-state property of microcontroller I/O pins. Only two I/Os are active at a time – one set to high and one set to low – while all other pins are in a high resistivity state. Only LEDs which are connected directly to the two active pins in the correct polarity will light up. LEDs on an indirect path, for example when two LEDs in series connect the active pins, will remain dark due to the nonlinear current-voltage properties of diodes.

Now, one has to wonder what happens when not two, but only one I/O is active? Nothing in the Charlieplexing scheme. But we can make use of it!

dice_circuitThe circuit above shows how to connect LEDs in a different scheme. In addition to the antiparallel pair between the two I/O pins, as customary with charlieplexing, LEDs are also connected to VCC and GND. The sum of forward voltages of the four LEDs in series (LED1-4 and LED5-8) is higher than 5V, so that they will not light up when PB0 and PB2 are in high impedance (Z) state.

When one PB0 or PB2 is H or L and the other pin is Z, sufficient voltage is present for a pair of LEDs to light up. However, when PB0 is H and PB2 is L, or vice versa, LED9 or LED10 are connected in parallel to a pair of LEDs. This will cause the majority of the current to flow through the single LED so that only LED9 or LED10 light up.


The table above shows a list of possible encodings. Two pins can drive six strings of LEDs! That is more than needed for a single die. Mission accomplished.

There is a caveat: The brightness of the single LED string is different from the two-led strings. This may require correction during multiplexing. However, in reality the difference in brightness is barely visible due to the logarithmic brightness perception of the human eye.

A quick test (LEDs not arranged in dice pattern) showed that the new multiplexing scheme works nicely. Note that the circuit relies on current limiting by the internal resistance of the AVR I/O ports. This does work, but is something that should be avoided in “real” designs…



A general analysis shows that the new scheme (“Charlieplex Plus”) can drive two LEDs per pin in addition to Charlieplexing. Therefore the number of LEDs for n pins is 2n+n²-n = n²+n. The table above shows the number of LEDs than can be driven with a given number of I/Os with different multiplexing schemes.

Should you use this for your next design? Probably not, because there are even more drawbacks and limitations than Charliplexing already has. But it is a nice hack!

So, in summary, the answer is: Two. Two I/O pins are needed to drive the 7 LEDs of an electronic die. Off to designing a PCB…

17 thoughts on “How many I/Os are needed to drive electronic dice?”

  1. You show states 8 (H/H) and 9 (L/L) as “Invalid”. But do any of the LED’s light up in those states? Or do you end up with not enough power to light the 1/2/5/6 or 3/4/7/8 combos?

    1. Well, of course these combos light up. But it is invalid in the sense that more than one LED lights up.

      There are similar situations in normal charlieplexing.

  2. Okay, so it’s just “invalid” logically, for your purposes. That was my guess, but I just wanted to be sure. 🙂

    BTW, good to see you post again, it’s been too long.

    1. It is probably the same, although you did not post the schematics. You also never explained how to arrive at the n³-1 figure, which is puzzling to me.

      I refuse though, to call any modification to an existing multiplexing scheme by any variation of “first-name-of-random-person plexing”. 🙂

      1. Good point about the schematics. Ive been meaning to add them for a while, but got distracted by other projects. I later made a 7+1 segment display using 1-wire by adding transistors, using only 2 pins. Each MCU pin has 3 states, so 9 different states for 2 pins with 1 state for all off leaves 8. It doesn’t scale easily like charlieplexing though; demuxing 27 states from 3 pins is a circuit I’m not about to try anytime soon.

      2. The Wikipedia article also links to some schemes where they use transistors to decode additional states. At some point the benefit becomes a bit questionable.

        Btw, you were probably referring to 3^n-1, the number of encodable nonzero states in a ternary system, instead of n^3-1 ?

    1. Well, but then you’d have to use a regular switch with an additional diode? I was aiming for a capacitive touch button, which takes 1 pin and zero components.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: