hansjny / Natural-Nerd

589 stars 444 forks source link

[SoundReactive2] Fading does not work properly #7

Closed hansjny closed 5 years ago

hansjny commented 5 years ago

When switching to fading mode on the sound reactive, sometimes it jumps to other colors

seriousrob commented 5 years ago

I have looked into your code to rebuild the project. I think i found the solution for your fading issue.

Checkt the function below. It works without jumping between colors for me on an ESP32.

void chillFade() {
  static int Anfang[3] = {0, 234, 255};
  static int Ende[3] = {255, 0, 214};
  static int Schrittweite = 512;
  static double SW[3];
  static double ZW[3];
  static bool reverse = false;
  static int counter = 0;
  if (fade == false) {
    for (int i = 0; i < NUM_LEDS; i++) {
      leds[i] = CRGB(Anfang[0], Anfang[1], Anfang[2]);
    }
    for(int i = 0; i<3; i++){    
      SW[i] = double((Ende[i] - Anfang[i])) / Schrittweite;
      ZW[i] = Anfang[i];
    }
    fade = true;
  }

  if (ZW[0] < Ende[0] && !reverse) 
  {
    for(int i = 0; i<3; i++){    
      ZW[i] += SW[i];
    }
  }
  else
  {
    for(int i = 0; i<3; i++){    
      ZW[i] -= SW[i];
    }
  }

  for (int j = 0; j < NUM_LEDS; j++){
    leds[j] = CRGB((int)round(ZW[0]), (int)round(ZW[1]), (int)round(ZW[2])); 
  }
  FastLED.show(); 
  delay(5);

  counter++;

  if (counter == (int)Schrittweite) {
    reverse = !reverse;
    if(reverse){
      for(int i = 0; i<3; i++){
       ZW[i] = Ende[i]; 
      }
    }else if(!reverse){
      for(int i = 0; i<3; i++){
       ZW[i] = Anfang[i]; 
      }
    }
    counter = 0;
  }
}
magicwoody commented 5 years ago

runs better now, vy good, tnx

SPrajc commented 5 years ago

This is perfect, it also removes the ocasional flicker <3

magicwoody commented 5 years ago

5 Lights working fine DSC_0125

adryyanbb commented 5 years ago

This is an amazing project. Unfortunately, I don't think I got the right code

vaibhav4verma commented 5 years ago

sketch_jun07a:4:29: error: reactive_common.h: No such file or directory

help me please