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()
{
turnOff();
}
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
{
turnOff();
pinMode(anodePins[n], OUTPUT);
pinMode(cathodePins[n], OUTPUT);
digitalWrite(anodePins[n], HIGH);
digitalWrite(cathodePins[n], LOW);
delay(refresh);
}
}
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?
