Turn on and off flickering led

I use an Wemos D1 Mini and i want to turn on/off 12v led that flickers with the Blynk app for iOS. (See my code under)

My wiring is correct because the led flicker if i just sett it in code, but i do not know how to make it flicker when i turned it on/off from the app. I can make the led turn on/off, but it does not flicker.

I’m not specially good with coding, and need som help to make this work.

    #define BLYNK_PRINT Serial
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>

    int powerled = 14;

    char auth[] = "***";
    char ssid[] = "***";
    char pass[] = "***";

    void setup()
    {
      Serial.begin(9600);
      Blynk.begin(auth, ssid, pass);
      pinMode(powerled, OUTPUT);
    }


    void candlelight(){
      if(powerled == HIGH){
        analogWrite(powerled, random(120) + 135);
        delay(random(300));
      }
    if(powerled == LOW){
      analogWrite(powerled, LOW);
    }
    }

    void loop()
    {
  Blynk.run();
  candlelight();
}

Someone…?

In C++ a value of 1 equals HIGH or true. A value of 0 equals LOW or false.

You are saying “set powerled to 14, then if powerled equals 1 do this, or if it equals 0 do that”

powerled isn’t equal to either 1 or 0, its equal to 14, so nothing will happen.

In addition to this logic issue, you also have a program structure issue. You should read this:
http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Pete.

I’m not understand. The code works. I can turn it on/off with the app. I just cant get the flickering to work…

I think i figured it out now. I just forgot to add timer setinterval under setup. It works fine now :slight_smile:

Thanks for trying btw :slight_smile:

No, i’m not figured it out i think.

i understand that i must run the flicker effect in loop for it to work, but i do not know how i can turn on/off the flickering led with a app button.

So, i’m still stuck here…