simple fade with TLC5490

hi all

i've got myself a TLC5490 because i wanted to do something quite simple with it, namely pulse some LEDs at a certain rate that would change when a sensor was triggered. having spent the day breadboarding the thing and trawling the arduino forum and other sites i've not got very far.

setting up the LEDs at original values is fine, i've got that - i can set an LED on each channel to a different value. i've been looking closely at the fade examples in the library but i can't get from there to just a regular fade on one channel. its not the done thing to ask for complete solutions on here and i'm not after that, but if someone could give a clumsy and slow programmer one or two clues he'd really appreciate it.

:relaxed:

having said that… substituting a channel number for ‘channel’ in ‘Fades’ seems to be getting there;

#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 = analogRead(0) * 2;
      int maxValue = 4095;
      uint32_t startMillis = millis() + 50;
      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();
}

the added bonus is that plugging my proximity sensor into analog in 0 is working without any additional code, though maybe it could be improved…

could someone clarify for me exactly what the ‘!tlc’, ‘uint16_t’ and ‘uint32_t’ are referring to i think i might just be able to get this done.

cheers

It is hard to follow that code it certainly will not do much. Did you write it! I say this because you are asking about the meaning of things in the code that you would have known if you wrote it. Also please show all your code not just a fraction because that misses out so much. Do you know for instance that it reads the analogue input pin 0, do you have a pot connected to this, if so what value?

! - is a logical NOT operation unit16_t - is an unsigned 16 bit interger variable unit32_t - is a n unsigned 32 bit interger variable

thanks for the response…

maybe i should have been a little clearer… the code snippet is from the ‘Fades’ example that comes with the tlc5490 library. i substituted the

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

for

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

which enabled me to control the LED on channel 1 (by changing the maths at ‘uint16_t duration’) instead of all of them. i have a Sharp GP2D12 sensor connected to analog 0 and i can change the fade speeds with it. all that is well and good.

what i am looking for is the syntax that allows me to say ‘the LED on channel 1 pulses at speed x unless analog 0 is y, the LED on channel 2 pulses at speed a unless analog 1 is b’ etc etc. i thought it might have something to do with uint16_t which is why i asked. i’m struggling to see where else in the example/s the individual channels of the chip are referenced.

this is the entire code of the test sketch i am using to work this out, using most of the ‘Fade’ example. with this i am able to work just with the LED on channel 1 and control its pulse rate with the sensor on analog 0;

#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 = 1200 - (analogRead(0) * 2);
      int maxValue = 4095;
      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();
}

This line:-

TLC_CHANNEL_TYPE channel;

tells you channel is not just a variable that you can substitute the constant 1 for.

You can’t do what you want with this code you will have to write your own.

yikes!

anybody got any tips for how to get started with that? i don't see anything in the examples that even suggests it...

i get as far as this

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



void setup()

 {
   Tlc.init();
 }

 void loop()
 {

 // a simple fade on...
 {
   tlc_addFade(1, 0, 4095, 200, 12000);
 }

 tlc_updateFades();

 }

but then making it fade off again, and making the fade on / fade off time dependent on whether the sensor has been triggered or not are still beyond me.

here’s another go at re-jigging the earlier code from the example, seeing as it builds in the analog pin reading and the fade in and out. despite grumpy mike saying this code wouldn’t do what i wanted i thought i’d try editing it more to see if it would get me close, to see which bits (if any) i could use.

the result of this is that there is some random length fading and flickering…

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

int duration = 0;
int startMillis = 0;
int endMillis = 0;

void setup()


{
  Tlc.init();
}

void loop()


{


  if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
    if (!tlc_isFading(1)) {
      if (analogRead(0) > 200);
      duration = 1000;
    }
    else uint16_t duration = 3000;
    int maxValue = 4095;
    startMillis = millis() + 50;
    endMillis = startMillis + duration;
    tlc_addFade(1, 0, maxValue, startMillis, endMillis);
    tlc_addFade(1, maxValue, 0, endMillis, endMillis + duration);
  }



  tlc_updateFades();

}

i guess something between the ‘tlc_addFade’ and what is going on here should be the solution.

but i don’t know how to get there… :~