Go Down

Topic: TLC5940 randomized fade and colour change. tlc_fades.h (Read 872 times) previous topic - next topic


So I'm trying to come up with a way to make a randomly twinkling, randomly colour changing set of 5 LEDs, that means its brightness varies randomly over time as does the hue independently. I'm using a TLC5940 to try and achieve this. However I'm not sure how to approach this, more specifically I'm not sure I fully understand how to use the fades extended library (tlc_fades.h).

would something like this be possible. This is pseudo-code, not part of any workable code yet, just me trying to see how I should approach the problem.

Code: [Select]
  if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
      uint16_t duration = twinkle_transition+random(twinkle_transition_offset);
      uint32_t twinkle_startMillis = millis() + 50;
      uint32_t twinkle_endMillis = startMillis + duration;
      duration = colour_transition+random(Colour_transition_offset);
      uint32_t colour_startMillis = millis() + 50;
      uint32_t colour_endMillis = startMillis + duration;

      for (int j=0; j<NUM_LEDS; j++){
       for (int i=0; i<3; i++){
         tlc_addFade(LED[j][i],Old_RGB[i],RGBArray1[i], twinkle_startMillis, twinkle_endMillis); //channel, fromRGB, toRGB, startMillis, endMillis
         tlc_addFade(LED[j][i],Old_RGB[i],RGBArray2[i], colour_startMillis, colour_endMillis);}}

what happens when you have overlapping timeframes for tlc_addFade? My guess is that there is no way this will work with tlc_addFade unless you split it up to calculate individual fades in each smaller random segment by doing a test for the smaller duration then calculating intermediate RGB values. What is your best approach for adding independent brightness and hue transitions?


Yes forget about the fade functions, they are blocking so you can only do one at a time. Look at the blink without delay example in the IDE and modify it to a fade without delay.

Go Up