I just built a multicopter, and it is cool. But to make it cooler, I wanted to install a dozen red leds an create a cylon effect. I was reading up on charlieplexing, and it looks to be the answer with a ATTiny85 (which I have a couple).
Anyway, I was looking at the library and it looked pretty simple, but then I saw the linked video below. He's got the LEDs dimming! That's exactly how I want to do it, but the library has it either "HIGH" or "LOW". So how did he do it?
You know, looking at the video, I don't think this is charlieplexing. He only has two LEDs on each pin. So how can you do the fade like that- one pin is clearly ground all the way, and two LEDs per pin. If you pause it, the two pins are at different brightness levels.
I suspect you'll find that the pairs of diodes are connected with reverse polarity, relying on the reverse breakdown voltage being greater than the forward voltage to avoid damaging the LED which is powered in reverse. Hence half the LEDs could be controlled active low with the common rail held high, and the other half would be powered active high with the common rail being held low. By modulating each LED fast enough, persistence of vision would make it appear to be a constant brightness. I don't see any separate current-limiting resisters for the LEDs, which is odd.
Do you think he's doing it like one frame at a time? If you freeze the video, the LEDs look the same every cycle. Maybe using PWM to turn on each pair as needed, pause 20ms or whatever, move to next "frame" and turn on each LED as needed, and so on? Sort of like stop motion animation?
Yes, he will be modulating the LEDs much faster than the video framerate. It's common to do this at hundreds of Hz, relying on persistence of vision (in the eye, and in the camera) to make each LED appear to fade.
Can you do that with a common ground/power? If they are all on the same rail, or bus, or whatever you want to call it, how would you vary the LEDs oriented towards their individual pin? IF #1 and #3 are at different brightnesses?
The 'common rail' is just another digital output pin so it can be set HIGH or LOW as you want to drive the pair of diodes forwards or backwards.
Because the rail is common to all the other diode pairs you will need to control all four diode pairs in parallel, but that's just a matter of managing the timing.
If I was implementing that I would generate a fixed frequency square wave on the 'common rail' and at the start of the 'high' part of that cycle I'd turn on all the odd LEDS, and then turn them off after an interval corresponding to the desired duty cycle for each LED; then do the same for the even LEDs during the 'low' part of the cycle. All it needs is an array of timer values and a couple of FOR loops to do the timing, using the approach demonstrated in the blink without delay example.