I'm working on a DIY project at home which needs approximately 150 LEDs to be lit up at varying levels of brightness. I'd eventually also like to have these LEDs lit in certain patterns so they really need to be driven by a microcontroller (a controllable LED matrix if you will).
After some consideration, I've started dabbling with the Ardunio as it seems to be suitable for the task at hand and allows me to multiplex LEDs and so on.
I have both the Arduino Uno and the Arduino Mega 2560. For testing I used the Mega as it has 15 PWM channels so I can adjust the brightness of each LED etc without having to mess about with different valued resistors and hook enough LEDs to give me a good idea of what's going on.
I had a good proof of concept up and running with LED1 lit up for 1800 microseconds, then switched off and LED2 lit up... and so on for all 15 LEDs. None of the LEDs were actually lit at the same time but it gave the persistance of vision effect (all LEDs appear lit up at the same time) and didn't draw a huge amount of current. This is what I'm aiming for, on a larger scale of ~150 LEDs.
So, next I needed to scale this up. The next proof of concept came in the form of utilising the TLC5940 LED driver after reading some articles and blogs online.
I hooked up the TLC5940 to the smaller Arduino Uno, and connected 16 LEDs to the 16 output channels of the chip. I ran a test program (I think it faded/ran patterns along the LEDs and it worked fine).
I then began writing a loop which would again switch on the first LED, wait for a fraction of second, then switch it off and move to the next LED.
The code worked up to about 3 LEDs but as soon as it hit the 4th LED, flickering could be observed. By the time it was scaled up to all 16 LEDs, there was a clear visible pattern (like a mexican wave) running across the LEDs.
I tried changing the delay time, reducing it all the way down to 1 microsecond but this had little effect.
My code was something like this:
#include "Tlc5940.h"
int DELVAR = 1
void setup()
{
Tlc.init(0); // initialise TLC5940 and set all channels off
}
void loop()
{
Tlc.clear();
Tlc.set(1, 4096);
Tlc.update();
delayMicroseconds(DELVAR);
Tlc.set(1, 0);
Tlc.update();
Tlc.clear();
Tlc.set(2, 4096);
Tlc.update();
delayMicroseconds(DELVAR);
Tlc.set(2, 0);
Tlc.update();
Tlc.clear();
Tlc.set(3, 4096);
Tlc.update();
delayMicroseconds(DELVAR);
Tlc.set(3, 0);
Tlc.update();
// ....and so on for all 16 channels .....
// (not optimal I know but at this point I'm still just getting my head around the logic)
}
Is there a limitation on the "speed" of the TLC5940 or the channels it's using from the Arduino?
How can I get around this so that all LEDs appear to be illuminated at the same time. Am I correct in thinking the duty cycle of the Arduino is 16MHz? and if so, shouldn't I theoretically be able to light up and switch off > 50,000 LEDs sequentially all in under one second?
Disclaimer - I have very basic electronic knowledge from when I was in school about 15 years ago so this is all a very steep learning curve for me!
NOTE: *For anyone wondering what it is I'm working on - it's a giant world map - the LEDs represent major urban or populated areas (cities etc) as viewed from space at nighttime. I'd eventually like these to be hooked up to realtime so that the LEDs lit up represent actual urban areas lit up at night at that particualr point in time - this is where the Arduino would be very useful.
It's a string art map based on one I did last year (below)
Only a lot bigger - it'll be 8ft x 4ft - progress so far - holes for LEDs drilled are ready: