Well OK, but one reason we recommend you search around this forum, Google, etc, is that while someone can write you some code… you still may not understand how it works… or it may not fit your needs exactly, thus needing more explanation, etc.
Also then this ‘usefull’ code only sorta benefits you … unless later on, someone else takes the time and effort to search for it
So to be clear… we do try to help, and will assist with code snippets when one at least shows they have tried… as you have done So take the time to break this supplied code down in your mind and you will slowly learn how it works…
You should be able to just fill in your WiFi/Auth info and flash this as is… although it doesn’t do any Blynk stuff on the App, just a simple Potentiometer and LED timed function. I did test it on my setup, and then modified for yours… so, hopefully not, but there may be a compile error or two for you to figure out
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth[] = "*********************************";
char ssid[] = "M******";
char pass[] = "*********";
#define led 2
int Flag = 0;
BlynkTimer timer;
void setup()
{
pinMode(led, OUTPUT); // Declare LED pin as output
Blynk.begin(auth, ssid, pass);
// Special lambda abstraction method of processing timer & called commands in compact form
timer.setInterval(1000L, []() { // Constant timer that check analog port every second
if (analogRead(A1) >= 500 && Flag == 0) { // Only processes following command if both analog and flag conditions are correct
Flag = 1; // Set flag to prevent further Pot action until ready again
FlashLED(); //Run LED function
}
});
}
void FlashLED() {
digitalWrite(led, HIGH); // Turns ON LED
// Special lambda abstraction method of processing timer & called commands in compact form
timer.setTimeout(5000L, []() { // Oneshot countdown timer that will turn OFF LED in 5 seconds
digitalWrite(led, LOW); // Turns OFF LED
});
// The preceding and following timers are processed immediately one after another, thus the staggered timeing
// Special lambda abstraction method of processing timer & called commands in compact form
timer.setTimeout(10000L, []() { // Oneshot countdown timer that will reset Pot check flag in 10 seconds
Flag = 0; // Resets flag
});
}
void loop()
{
Blynk.run();
timer.run();
}
I am still trying to understand timers myself and am quite proud of this example It is however, using a more compact form of the normal timer layout… that usually consists of the timer/timeout command, pointing to another void function, that then contains the action commands. Check here for what I mean (just one of many repeated examples spread around this forum).