Four digit LED display CHARLIEPLEXED

In a previous project I used a 4 digit 7 segment display.
I was short of pins so I used 2 A6276 16-Bit Serial Input, Constant-Current
Latched LED Drivers.

This only used 3 digital pins.

I wrote a library for this display:,7866.0.html

In my current project for the 4 digit 7 segment display I used charlieplexing.
Wikipedia, the free encyclopedia has a description.

This uses 8 digital pins and no extra components:

The program is interupt driven. TIMER2(Arduino PWM 3 and 11)
generates interupts every 720 usec.
The program uses less than 1% of CPU time.
It uses 30 bytes of RAM and 900 bytes of flash.

The CMOS digital pins provide a peak drive current of 45 mA.
Each segment of the 28 is driven once every 20 msec.
This gives 1.6 mA average current per segment.
If the display is not bright enough use high intensity displays.

The code is all in a class which has 4 functions:

This sets up Timer2 and starts interupts.

This stops interupts and puts the digital pins into tristate.

DisplayI(int number)
This displays numbers in the range 0000 to 9999.
If it is not in the range “EEEE” will be displayed.

DisplayP(long picture)
Picture is 32 bits which map to each segment.

x is dont care. A 1 lights the segment a 0 turns it off.
7 segment display:


| |
| |
f | | b
| |
| |

| |
| |
e | | c
| |
| |


The library has 2 examples. To demonstrate counting:

//simple program to demonstrate counting

#include <CHARLIESEVEN.h>

unsigned int d = 0;

void setup()
}//end of setup

void loop()
d +=1;
}//end of loop

Down load fourdigitLEDC from:

Brilliant work!

That’s going in my bookmarks. :wink:

– edit –
So, even illumination? any flicker? I have never tried Charlieplexing, the lack of series resistors and 8 diodes on one pin scare me a little. I guess you have to be very careful to program your Arduino BEFORE you connect up the hardware, in case you have outputs set high from the previous sketch

Hi Carl,

Thank you for sharing a nice project.

May I ask if there's a way to avoid spreading those eight pins across multiple ports? With the crystal using two PORTB pins, is there even a full eight bit port available on Arduino w/328P?

Cheerful regards, Mike

Thanks Si,

No flicker - 50 hz refresh rate.

Constant light output per segment - 1.6 mA per segment. This is a lower output than is possible from the displays but for indoors it's OK. To increase the output for high ambient light using this circuit you should use high intensity displays.

You dont need to be careful. No combination of bits can damage the display diodes.

Thanks Mike,K8LH

Thanks also for your email which I have answered.

You are right PORTB only has 6 pins available(XTAL) PORTC only has 5 available.

PORTD does have 8 available but PD0 and PD1 are used for the Arduino bootstrap loader.