TLC5940 problem

Hello,
I'm having an issue with my program i guess. this link is the video of it working.
eventually it shuts off on its own.

turn off your speakers if you aren't 18 or over please

#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;

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

void loop()
{
  int channelOne = random(15);
  int channelTwo = random(15);
  int channelThree = random(15);
  int channel = 0;
  int maxValue = 4095;
  if (channelOne == channelTwo || channelThree)
  {
    channelTwo = random(15);
    channelThree = random(15);
  }
  
  if(channelTwo == channelThree)
  {
    channelThree = random(15);
  }  
  
  if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
    if (!tlc_isFading(channel)) {
      uint32_t startMillisOne = millis();
      uint32_t endMillisOne = millis() + 10000;
      uint32_t startMillisTwo = millis() + 5000;
      uint32_t endMillisTwo = millis() + 15000;
      uint32_t startMillisThree = millis() + 7500;
      uint32_t endMillisThree = millis() + 17500;
      tlc_addFade(channelOne, 0, maxValue, startMillisOne, endMillisOne);
      tlc_addFade(channelOne, maxValue, 0, endMillisOne, startMillisOne);
      tlc_addFade(channelTwo, 0, maxValue, startMillisTwo, endMillisTwo);
      tlc_addFade(channelTwo, maxValue, 0, endMillisTwo, startMillisTwo);
      tlc_addFade(channelThree, 0, maxValue, startMillisThree, endMillisThree);
      tlc_addFade(channelThree, maxValue, 0, endMillisThree, startMillisThree);
    }
  }
  tlc_updateFades();
}

Anybody find anything?

funkyguy4000:
Anybody find anything?

Yes. I believe you're still having a problem with your if statement

if (channelOne == channelTwo || channelThree)

The "OR" clause will be true if channelThree is non-zero. Is that really what you want?

I'd expect something like this

if (channelOne == channelTwo) || (channelOne == channelThree)

Also have you tried the example code to see if it works as it should?

I hope this helps,

Brad (KF7FER).

EDIT: So do you understand that there is a single channel no matter how many TLC5940's you've got? So a channel value of 0-15 is the first TLC5940, 16-31 is the second, etc. Just unsure what your code is supposed to do.

Also you've got this

TLC_CHANNEL_TYPE channel;

And then you use channelOne, channelTwo, and ChannelThree. You probably want to define them as non-int just to be proper.

Ah yes, i forgot to change that.

Also i don't know exactly what "TLC_CHANNEL_TYPE channel" really does. I have seen it in every tlc5940 code so i figured i would need it

funkyguy4000:
Also i don't know exactly what "TLC_CHANNEL_TYPE channel" really does. I have seen it in every tlc5940 code so i figured i would need it

It defines a variable called 'channel' as the type TLC_CHANNEL_TYPE.

This is the type of variable that should be used when you call tlc_addFade, not an int like you're doing. To be pedantic

TLC_CHANNEL_TYPE channelOne, channelTwo, channelThree;
...

tlc_addFade(channelOne, ...

BTW, this is a problem as well

    if (!tlc_isFading(channel)) {

You defined channel but you never used it in a fade. Again, what I think you want is

    if (!tlc_isFading(channelOne) && !tlc_isFading(channelTwo) && !tlc_isFading(channelThree)) {

That might help :slight_smile:

Brad (KF7FER)

I'm not sure if it will help or not, but this is how I do fades

// Fade in effect 
void fadeIn(void) {
  TLC_CHANNEL_TYPE sideChannel;
  
  uint32_t startMillis = millis() + 10;
  uint32_t endMillis = startMillis + UP_DURATION;

  for (int indx = 0; indx < NO_LIT_LEDS; indx++) {
    channel = CHANNEL_BASE + (NO_SEGMENTS * indx);
    tlc_addFade(channel,    0, MAX_VALUE,       startMillis, endMillis);
    
    if (multiLED) {
      // now for the "side" channels, starting with the LEFT side
      if (channel == CHANNEL_BASE)
         sideChannel = CHANNEL_BASE + lastChannel;
      else
         sideChannel = channel - 1;
   
      tlc_addFade(sideChannel, 0, MAX_SIDE_VALUE, startMillis, endMillis);    
    
      // finally the RIGHT side channel
      if (channel == CHANNEL_BASE + lastChannel)
         sideChannel = 0;
      else
         sideChannel = channel + 1;
       
      tlc_addFade(sideChannel,  0, MAX_SIDE_VALUE, startMillis, endMillis);
      }
    }

  while (tlc_isFading(channel))  
     tlc_updateFades();
  }

Note that the function doesn't exit until the fade effect is complete.

Also 'channel' and 'lastChannel' are globals define as TLC_CHANNEL_TYPE.

Maybe this will help you see a different way to do things,

Brad.

EDIT: I should add that I've actually got 3 TLC5940's and I'm lighting LEDs in a circular pattern. But what happens in the for loop really doesn't matter, maybe just try and setup your fades first then have the while/tlc_updateFades loop.

Hello,

I dont know if you are still interested in the question what is TLC_CHANNEL_TYPE:
Here it is:
It' the type definition of the channel variable, which is usually unsigned char. This means you can daisy chain 16 TLC with 16 channels = 256 channels.
If you connect more than 16 TLC's in a chain you must change the type to int otherwise you could not address the 17th TLC you would access the first one...

Best regards

Andreas

Actually that does help out a lot!
Thank you