BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

End while loop by pressing button

Hello,

I have an Arduino Uno, an Esp8266 and a LED-Strip (WS2812) and try to implement functions by pressing a button. The functions work fine, but I´m not able to read out a new pin value from my virtual pin in my while-loops of my functions to end the function. I always have to shut down my esp8266 to control my LED-strip again. Can someone give me the solution for this? Thanks in advance!!

Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.

int valueV6;
int data = 50; 

BLYNK_WRITE(V6)  // Here is one of my functions, which read out virtual pin V6
{
  valueV6 = param.asInt();
  if(valueV6 == 1)
  {
    static1(0,0,0,0);    //static1 is a function which sets static values to my LED-strip(it is shut off here)
    delay(30);
    effect3();               
    }

    else{
      static1(r,g,b,data);
      }
  }

 void effect3()
 {
  int n = 0;
  int m = 0;

  while(valueV6 == 1)
  { 
    for (int i = 0; i < 256; i++)
      {
      leds1[n] = CRGB(50,50,50);
      FastLED.setBrightness(i);
      delay(1);
      FastLED.show();
      }
    for (int i = 256; i > 0; i--)
      { 
      leds1[n] = CRGB(50,50,50);
      FastLED.setBrightness(i);
      delay(1);
     FastLED.show();
      }

    FastLED.clear();           // around here I would like to read out the virtual pin V6 again, to eventually
    n++;                              // end the while loop, if the button is set to 1/LOW
    if (n == 60)                    // valueV6 = param.asInt(); does unfortunately not work!
      {
      n = 0;
      }
    }
  }

void static1(int r, int g, int b,int brightness)
{
  
  for (int i = 0; i < NUM_LEDS1; i++ )
  {
    leds1[i] = CRGB(r, g, b);
  }

    if(pinValue == HIGH){
    FastLED.setBrightness(brightness);
    }
  else{
    FastLED.setBrightness(0);
    }  
  
  FastLED.show();
  
}

Read this about while loops…

Pete.