Pages: [1]   Go Down
Author Topic: How do I change the speed of fading with Tlc5940?  (Read 691 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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();
}
« Last Edit: October 10, 2012, 01:06:18 pm by kraken667 » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8940
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
      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:
      unsigned long duration = 10000; // Decay over 10 seconds
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8940
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: