TLC5940 + FSM, trying to time fades

Hello,

I would like to be able to have 10 RGBs fading in and out at different intervals. I have two TLC5940s daisychanied and ran by an UNO. I have tried for hours and hours trying to figure this out.

Any help or input is much appreciated.

Below is my best attempt at making this work. In this attempt the 21 channel turns on and stays on.

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

TLC_CHANNEL_TYPE channel;

int led1State = 0;

long int led1time = 10UL;

unsigned long count1 = 0;

boolean timeout(unsigned long *marker, unsigned long interval) {
  if (millis() - *marker >= interval) { 
    *marker += interval;   
    return true;       
  } 
  else return false;
}

void setup(){
  Tlc.init();
  led1time = 1UL;
  led1State = 0; 
}

void loop() {
 if (timeout(&count1, led1time )) {
    switch (led1State) {
    case 0: 
      {                              
        led1State = 1;               
        led1time = 10000UL;            
        RGBfade();
        break; 
      }

    case 1: 
      {
        led1State = 2;               
        led1time = 5000UL;           
        RGBfade();
        break; 
      }

    case 2: 
      {
        led1State = 3;
        led1time = 4000UL;
        RGBfade();
        break; 
      }

    case 3: 
      {
        led1State = 4;
        led1time = 5000UL;
        RGBfade();
        break; 
      }
    case 4:
       {
        led1State = 5;
       led1time = 10000L;
    RGBfade();
       break; 
       }
    case 5:
       {
        led1State = 0;
       led1time = 5000UL;
       RGBfade();
       break;   
    }
   }
  }
 }


void RGBfade(){
  
    if (!tlc_isFading(channel)) {
      uint16_t duration = 2000;
      int maxValue = 4095;
      uint32_t startMillis = millis() + 50;
      uint32_t endMillis = startMillis + duration;
      tlc_addFade(21, 0, maxValue, startMillis, endMillis);
      tlc_addFade(21, maxValue, 0, endMillis, endMillis + duration);
    }
  tlc_updateFades();
}

In this attempt the 21 channel turns on and stays on.

I fail to see where you have 21 of anything.

Why does timeout take a pointer?

@ Paul

21 is in

 tlc_addFade(21, 0, maxValue, startMillis, endMillis);
      tlc_addFade(21, maxValue, 0, endMillis, endMillis + duration);

The pointer changes each state after a certain amount of time.

I will eventually have multiple RGBfade(); style functions for each channel.

Any ideas to help make this work, or even another path I should be on?

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

It might help if you posted these, too. Are they custom functions you coded?

Those refer to the TLC5940 library.

1rulon1:
Those refer to the TLC5940 library.

Be nice to see a link to that library...

TLC5940 library:

https://code.google.com/p/tlc5940arduino/

From what I remember tlc_addFade is a blocking function and so you can not use more than one at once.

Thank you Mike.