Hi everyone,
I’ve been playing with tlc5940 and trying to understand how to write software for it.
I’m trying to use for loop to fade leds.
For testing I did the following loop
#include "Tlc5940.h"
#include "tlc_fades.h"
void setup()
{
Tlc.init(4095);
Serial.begin(9600);
}
void loop()
{
int start = 0;
int finish = 1000;
for (int led=0; led < 7; led++)
{
tlc_addFade(led ,0, 4095, start, finish);
start = start + 200;
finish = finish + start;
}
tlc_updateFades();
}
This works as expected and fades leds
No I want o start fading leds on trigger so I put the same loop into if condition
#include "Tlc5940.h"
#include "tlc_fades.h"
int val = 1000;
int go = 0;
void setup()
{
Tlc.init(4095);
Serial.begin(9600);
}
void loop()
{
val=analogRead(0);
Serial.println(val,DEC);
delay(500);
if (val <= 600 && go == 0 )
{
go = 1;
int start = 0;
int finish = 1000;
for (int led=0; led < 7; led++)
{
tlc_addFade(led ,4095, 0, start, finish);
start = start + 200;
finish = finish + start;
}
tlc_updateFades();
}
}
Now instead fading the leds just light up.
What am I doing wrong?
Thank you