Tlc5940 and Fades.
I have designed a model lighthouse, it consists of a circle of 8 star LED's powered by a 1000 mA Buckpuck. The LEDs are switched on by a PNP transistor. The switching is controlled by a Tlc5940 and an arduino.
The intention is to create the effect of rotation having the LEDs fade up to a maximum and then fade down.
I used the code from acleone to control the Tlc5940. I can get the examples in the library to function as expected.
Here is the circuit. I omitted the arduino and only have shown the pins for clarity. In addition, I have only shown 4 LED's. The code is below.
I can easily get the circuit to rotate through the LED's but am having difficulty with the fading. Searching the web does not bring up much in the way of fade examples.
Specifically I am unclear if I need to use the fade buffer or remove any of the fades after they have been used. I need to get the code written so that at any one time, one LED is fading down, the next LED is fading up and all others are off.
If I use the code as written, at any one time I have three LED's lit and one will turn off. They will progressively increase in brightness in a jerky manner and will not fade down, rather they drop from max to zero.
Any suggestions on both the circuit and the code would be appreciated.
Thanks in advance.
Iain G.
Arduino Diecimila
#include "Tlc5940.h"
#include "Tlc_fades.h"
/* Code to cycle through 4 leds placed in a circle,
fading them up and then down. Intended for use in a model lighthouse.*/
int startingLux = 0; // starting luminosity level for fade up, endpoint for fade down.
int maxLux = 250; // peak brightness level.
uint32_t currentMillis = 0;
uint32_t endMillis = 0;
int fadeTime = 2500; // Time over which LED's are meant to fade up and fade down.
void setup()
{
Tlc.init();
}
void loop()
{
int channel = 1;
while (channel < 5) // In this example have 4 LED's, final model will have 8
{
switch (channel)
{
case 4:
currentMillis = millis() + 25;
endMillis = currentMillis + fadeTime;
tlc_addFade(channel, maxLux, -250, currentMillis, endMillis);
tlc_addFade(1, startingLux, maxLux, currentMillis, endMillis);
break;
default:
currentMillis = millis() + 25;
endMillis = currentMillis + fadeTime;
tlc_addFade(channel, maxLux, -250 , currentMillis, endMillis); // Code does not fade down.
tlc_addFade(channel + 1, startingLux, maxLux, currentMillis, endMillis); //Fade up is jerky.
}
tlc_updateFades();
Tlc.clear(); //Using his to turn all LED's off but does not appear to be working.
Tlc.update();
delay(fadeTime); //
//delay (2750); //If I add in this extra delay,only two LEDs light at any one time.
tlc_removeFades(channel -1 ); //Unsure what this does?
channel++;
}
/*
tlc_removeFades(1);
tlc_removeFades(2);
tlc_removeFades(3);
tlc_removeFades(4);*/
}