Pages: [1]   Go Down
Author Topic: TLC5940 randomized fade and colour change. tlc_fades.h  (Read 480 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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;
     

      RGBArray1=HSBtoRGB(Hue,saturation,brightness+random(brightness_offset);
      RGBArray2=HSBtoRGB(Hue+random(hue_offset),saturation,brightness;
      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?
 
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 619
Posts: 33980
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: