Blink Time Control with Slider

Hello,
best wishes from Germany :slight_smile: .
I need help with my little Projekt.
I want to blink a Digital Output (DO23) if Button V0 is ON and control the Blink ON Time with Slider V1 (0sec.-5sec.) and Blink OFF Time with Slider V2 (0sec.-5sec.)
But if i do it like that, the LED ist permanent ON. How can i control the delay time withe the Slider?

Best wishes,
Patrick




/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "YourTemplateID"


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxx";
char pass[] = "xxx";


int dunkel=0;
int hell=0;
int ein=0;





BLYNK_WRITE(V0) {
  if (param.asInt()) {  // If receiving a 1
    ein=HIGH;

    Serial.println(ein);
    
}

    else { ein=LOW;
    Serial.println(ein);}
  
    }

   
  

  BLYNK_WRITE(V1)
{
  //reads the slider value when it changes in the app
  
  int hell = param.asInt();
 Serial.println(hell);
 
}

 BLYNK_WRITE(V2)
{
  //reads the slider value when it changes in the app
  
  int dunkel = param.asInt();
  Serial.println(dunkel);

}








void setup()
{
  pinMode(23, OUTPUT);
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);


}




void loop()
{
  Blynk.run();

 if (ein == HIGH) {
        digitalWrite(23, HIGH);
    delay(hell);
    digitalWrite(23, LOW);
    delay(dunkel);
    }


 }

Search for “blink without delay” on google.
Set the blink delay / interval with slider.

You’re doing a number of things wrong,

In addition to the cluttered void loop and use of blocking delays, your dunkel and hell variables are being declared globally, then re-declared in your BLYNK_WRITE(V1) and BLYNK_WRITE(V2) callback functions…

the int command before these param.asInt() commands is re-declaring these variables locally, and preventing the widget values from being visible outside of the callback functions.

You should probably use lambda timeout timers instead of delays to implement the mark-space ratio for flashing your LED. See the “Timeout Timers” section of this topic for more info…

Pete.

Hello Pete,
thank you for your help.
I try to understand it but i dont :see_no_evil:
Maybe you can change my code so that it work? :see_no_evil:

Patrick

I’d suggest that you take some time to improve your C++ coding skills so that you are able to stand things like variable scope and the use of timeout timers.

Pete.