Blink.inject with WS2812 fading

Hello,

I have an issue with the function “BlynkProvisioning.run ();” and my leds WS2812.
When I apply a fading effect some leds start to flash another color.

I think of a problem of interruption, do you have an idea?


#define USE_CUSTOM_BOARD          // For all other ESP8266-based boards -

#define APP_DEBUG        // Comment this out to disable debug prints

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG

#define PIN_WS2812  5                     // Set if your LED is WS2812 RGB
#define NBPIXELS    6                     //nombre de pixels

#include <Adafruit_NeoPixel.h>
#include "BlynkProvisioning.h"

struct RGB {
  byte r;
  byte g;
  byte b;
};

RGB LedColor = { 255 , 255 , 255 };

//quand isShowing = true, l'effet de "respiration" s'affiche
bool isShowing = false;

//moment à partir duquel on a lancé l'effet. Sert à savoir quand l'arrêter
uint32_t startTime = 0;
unsigned long breathe_time = millis();

//délai entre deux tours de boucle de l'animation "respiration". Plus la valeur est faible, plus la respiration est rapide
int breathe_delay = 10;
//durée de l'effet de respiration, en millisecondes
uint32_t duration = 13.1 * 1000L;

#define EFFECT_START_VALUE  100
int i = EFFECT_START_VALUE;

Adafruit_NeoPixel strip = Adafruit_NeoPixel( NBPIXELS, PIN_WS2812, NEO_GRB + NEO_KHZ800);

// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
  }
}

BLYNK_WRITE(V0) {
  LedColor.r = (byte)param[0].asInt();
  LedColor.g = (byte)param[1].asInt();
  LedColor.b = (byte)param[2].asInt();
  isShowing = true;
  DEBUG_PRINT("New color "+String(LedColor.r)+" "+String(LedColor.g)+" "+String(LedColor.b));
}

void setup() {
  delay(500);
  Serial.begin(115200);

  //initialisation des deux rubans de LED
  strip.begin();
  strip.Color(0, 0, 0);
  strip.setBrightness(0);
  strip.show();

  BlynkProvisioning.begin();
}

void loop() {
  // This handles the network and cloud connection
  BlynkProvisioning.run();

  Leaf();
}

void Leaf() {
  //ce passage permet de lancer l'effet pour un certain temps.
  //lorsque le temps est écoulé, on conserve la couleur avec la luminosité au max.
  if (isShowing == true) {
    if (startTime == 0) {
      startTime = millis();
      i = EFFECT_START_VALUE;
    }
    //on vérifie ici si le temps alloué est écoulé.
    if ((millis() - startTime) < duration) {
      LeafBreath();
    } else {
      startTime = 0;
      isShowing = false;
    }
  }  
}

//cette fonction gère l'effet de "respiration" en calculant, à partir d'une fonction à base sinusoïdale.
//Source: https://arduinoelectronics.wordpress.com/2015/05/12/non-blocking-breathing-led/
void LeafBreath() {
  if ( (breathe_time + breathe_delay) < millis() ) {
    breathe_time = millis();
    float val = (exp(sin(i / 2000.0 * PI * 10)) - 0.36787944) * 108.0;
    for (int n = 0; n < strip.numPixels(); n++) {
      strip.setPixelColor(n, strip.Color(LedColor.r, LedColor.g, LedColor.b));
    }
    strip.setBrightness(val);
    strip.show();
    i++;
  }
}