Go Down

Topic: How do I change the speed of fading with Tlc5940? (Read 732 times) previous topic - next topic

kraken667

Oct 10, 2012, 08:03 pm Last Edit: Oct 10, 2012, 08:06 pm by kraken667 Reason: 1
Hey, fresh meat here! I´ve just recently discovered Arduino and could use some help. I´m going to have 32 LEDs fading with seperate speeds in a organic way. I´ve been using example codes for some hours now, but the fading is way too rapid. I don´t know how to make a single LED to fade slow and smooth. Can you help me?

Below is the code I´m using right now, testing one LED. How do make the fading slower here?
Code: [Select]
#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;

void setup()
{
 Tlc.init();
}

void loop()
{
 if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
   if (!tlc_isFading(1)){
     uint16_t duration = 3000 - (analogRead(0) * 2);
     int maxValue = 4000;
     uint32_t startMillis = millis();
     uint32_t endMillis = startMillis + duration;
     tlc_addFade(1, 0, maxValue, startMillis, endMillis);
     tlc_addFade(1, maxValue, 0, endMillis, endMillis + duration);
     }
     
   if (channel++ == NUM_TLCS * 16) {
     channel = 0;
   }
 }
 tlc_updateFades();
}

johnwasser

I'd think that you could change the speed of fading by changing 'duration'.  Currently it is set by an analog input on A0:
Code: [Select]
      uint16_t duration = 3000 - (analogRead(0) * 2);

That will get you between 954 milliseconds (about a second) and 3000 milliseconds (three seconds).

You can make the decay time a constant:
Code: [Select]
      unsigned long duration = 10000; // Decay over 10 seconds
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kraken667

Thank you johnwasser! Great...

Now, if I don´t want a total fade out, so that the LEDs never go down to zero, how do I make that happend?

johnwasser


Now, if I don´t want a total fade out, so that the LEDs never go down to zero, how do I make that happend?


I'd guess that you'd set the start or end point of the fade to something other than zero.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kraken667

Thanks again! Sorry for being such a neebie...

Go Up