Tlc5940 fading question

Hello,

So I love the TLC5940 and I decided to try something that I haven’t done before. Govern the fade value by using equations. I am using RGB Leds and they are connected to the TLC5940 and I have differentiated the pins by color and then given each color its own equation. The equations shouldn’t be exceeding 255.
Here is my code.

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

int Red[] = {4,7,10,13,16};
int Blue[] = {2,5,8,11,14};
int Green[] = {3,6,9,12,15};

int Rval = 127*sin(millis()) + 127;
int Gval = 127*sin(millis()/2)+127;
int Bval = 127*sin(millis()/3)+127;


TLC_CHANNEL_TYPE channel;

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

void loop()
{
  int instR1 = Rval;
  int instG1 = Gval;
  int instB1 = Bval;
  delay(50);
  int instR2 = Rval;
  int instB2 = Bval;
  int instG2 = Gval;
  
  int start = millis()+50;
  int end = start + 1000;
  for (int i = 0; i<5; i++)
  {
    tlc_addFade(Red[i],instR1,instR2,start, end);
    tlc_addFade(Blue[i],instB1,instB2,start,end);
    tlc_addFade(Green[i],instG1,instG2,start,end);
    tlc_addFade(Red[i],instR2,instR1,start,end);
    tlc_addFade(Blue[i],instB2,instB1,start,end);
    tlc_addFade(Green[i],instG2,instG1,start,end);
    Tlc.set(0,255);
  }
 tlc_updateFades();
 instR1 = 0;
 instG1 = 0;
 instB1 = 0;
 instR2 = 0;
 instB2 = 0;
 instG2 = 0;
}

Now the issue that i’m having is the colors aren’t changing at all. They have a color and they are just chilling in that same color even though I have the functions being changed in the loop.

Anybody got an idea whats going on?

This only happens once. When the program initializes, these "equation" are calculated and stored in Rval, GVal, and Bval.

int Rval = 127*sin(millis()) + 127; int Gval = 127*sin(millis()/2)+127; int Bval = 127*sin(millis()/3)+127;

They will never change after this.

So later when you assign Rval to something, it is this pre-determined calculated value that gets stored. If you want to calculate them in your loop with millis() changing, you must do the calculation again.

so I would just have to set it equal to the equation again?

Yes, you must do the calculation each time one of its variables change.

Okay, its working now! thank you.

int Rval = 127*sin(millis()) + 127;

The sin() function takes a value in radians, not a time.

I don’t need a specific value, I just need a value that can change each time I run it. It works fine.