Multiple LEDs on with Charlieplexing

He, I’m just working with arduino, C and charlieplexing for a couple of hours so forgive me if I ask any real stupid questions.

I’m planning of making a ball covered with LED’s where i’ve got to control each led sepperratly and multiple leds can be on at the same time. Right now I’ve got 12 LEDs on 4 pins working and using a refresh rate of 20 / “number of leds on” (which i think should be 50Hz) i can even light multiple Leds at the same time. But this last thing becomes a problem when more than 3 LEDs are lid, the brightness drops a lot and they start to flicker a lot.

My code so far:

int numLeds = 12;
int numPins = 4;
int anodePins[] = {2,3,2,4,2,5,3,4,3,5,4,5};           // Anode of pin n
int cathodePins[] = {3,2,4,2,5,2,4,3,5,3,5,4};         // Cathode of pin n
int ledPins[] = {2,3,4,5};                             // All pins used
int ledsOn = 3;                                        // Variable to change the amount of LEDs on

void setup()

void loop()
  int refresh = 20 / ledsOn;                            // Sets the refresh rate to 50 Hz
  for (int n = 0; n < ledsOn; n++)                      // Turns the first n LEDs on, where n is equal to the variable ledsOn
    pinMode(anodePins[n], OUTPUT);
    pinMode(cathodePins[n], OUTPUT);
    digitalWrite(anodePins[n], HIGH);
    digitalWrite(cathodePins[n], LOW);

void turnOff()                                          // Turns all LEDs off
  for (int i = 0; i < numPins; i++)
    pinMode(ledPins[i], INPUT);

I read somewhere that there is an option of using different patterns where multiple LEDs are lid to reduce the frequency. Which makes it possible to split every possible situation into a number of patterns which are then used instead of every single LED in every loop. Problem is, i can’t find any hints as how to start programming for this. Are there any people who have done this before and could help me with this?

What about splitting up the leds into multiple groups with each group having its own set of pins? 2 pins for 3 leds and you’d never have more than 3 on a set list. Software would be complicated I guess.

As far as I know the idea of charlieplexing is reducing the amount of pins needed to control a certain amount of leds. Two pins for 3 leds wouldn’t be a great win in reducing pins (of which i cant see yet how i would do that, even with charlieplexing i could only control 2 leds on two pins).

I attached a picture of all 12 leds burning using charlieplexing and frequency, but as you can see the brightness of each led is very limited.

using different patterns where multiple LEDs are lid to reduce the frequency.

You have to look at your charleplexing schematic and identify what leds you want on at the same time. Then work out what combination of high low and disabled states you need the pins to be in to achieve this state. Then make those pins that output state.

Problem is that some groupings are imposable to achieve like this and you have to split them up into sub groups.

Then to drive this you have to store the high, low and disabled states in an array and cycle through that array to get them to display.

This is very specific to what patterns you want to use and doesn’t lend itself to a universal solution.

Sounds like you’d be better off using some 74HC595’s or other LED Driver IC’s. It would make it a lot simpler.

He thanks for the reactions. I’ve been looking at LED drivers, but have a hard time finding a good explanation as to how they work. And how i could control them, does any have a link with a good tutorial?

Just now i found the microdelay() function which compleetly removes the flickering of the leds but ofcourse doesn’t increase brightness. Turn side on this is that i just increased the amount of leds from 12 to 20 (5 pins) without a great loss in brightness, if i can increase this to 56 (8 pins) without any big loss in brightness i could solve it with just putting brighter leds in it (now im just using basic red leds).

i could solve it with just putting brighter leds in it

Just lower the series resistor LEDs can take in general about 3 times the current if it is pulsed than if it is continuous.

you might want to check out the code and circuits used here