Hello i have been trying to blink a led using esp 8266 (for a pattern) . I know how to do it using delay but i want to do it using time.settimeout function . now below is the code i did but it didnt work for me .
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "auth_token"; // enter the new code
char ssid[] = "Freedom";
char pass[] = "pajik@1234";
const int ledPin = 5 ;//D1 pin pwm pin.
int x = 0 ; // virtual pin 2
BlynkTimer timer ; // creates a time object called timer
int ledState = LOW; // initally making the ledstate zero.
BLYNK_CONNECTED() {
Blynk.syncVirtual(V2);
}
BLYNK_WRITE(V2) {
ledState = param.asInt();
if (ledState == 1 ) {
while (x > 15) {
ledState = ! ledState ;
digitalWrite (ledPin, ledState);
timer.setTimeout(5000L, actionoff);
}
x = 0 ;
ledState = 0 ;
Blynk.virtualWrite (V2, ledState); // updating the button widget in the app
digitalWrite(ledPin, ledState); // switches off the led
}
}
void actionoff() {
x = x + 1 ;
}
void setup() {
Serial.begin(9600);
WiFiManager wifiManager;
wifiManager.autoConnect("auto_connect_ap");
Serial.println("connected :)");
Blynk.begin(auth, ssid, pass, IPAddress(xx, xxx, xx,xx), 8080);
pinMode (ledPin , OUTPUT);
digitalWrite (ledPin, LOW );
}
void loop() {
Blynk.run();
timer.run();
}```
this is my normal code which i used to blink the led using the delay function.
ledState = param.asInt();
while (x < 15) {
ledState = ! ledState ;
digitalWrite (ledPin, ledState);
x = x + 1;
delay(100);
}
x = 0 ;
ledState = 0 ;
Blynk.virtualWrite (V2, ledState); // updating the button widget in the app
digitalWrite(ledPin, ledState); // switches off the led
}```
@Gunner i would really like to thank you , since every post that i have posted in this forum , you have taken your time to reply to those posts. people like you make this world a better place.