my last code :
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <SPI.h>
#include <Wire.h>
BlynkTimer timer;
char auth[] = "xxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxx";
// Set your LED and physical button pins here
const int relais1 = 14;
const int btn1 = 27;
const int ledV1 = 5;
const int ledR1 = 2;
int relais1Sate = LOW;
int btn1State = HIGH;
int ledV1State = LOW;
int ledR1State = LOW;
BLYNK_WRITE(V1) {
relais1Sate = param.asInt();
Serial.print("Widget Button V1 changed. Writing ");
Serial.print(relais1Sate);
Serial.print(" to Relay 1 and LED V1, and ");
Serial.print(!relais1Sate);
Serial.println(" to LED R1 ...");
digitalWrite(relais1, relais1Sate);
digitalWrite(ledV1, relais1Sate);
digitalWrite(ledR1, !relais1Sate);
}
void checkPhysicalButton1()
{
if (digitalRead(btn1) == LOW)
{
Serial.print("Location A, btn1 = ");
Serial.print(digitalRead(btn1));
Serial.print(" btn1State = ");
Serial.println(btn1State);
// btnState is used to avoid sequential toggles
if (btn1State != LOW)
{
Serial.print("Location B, btn1 = ");
Serial.print(btn1);
Serial.print(", btn1State = ");
Serial.println(btn1State);
// Toggle LED state
relais1Sate = !relais1Sate;
Serial.print("Location C, writing ");
Serial.print(relais1Sate);
Serial.println(" to Relay 1 ...");
digitalWrite(relais1, relais1Sate);
ledV1State = !ledV1State;
Serial.print("Location D, writing ");
Serial.print(!ledV1State);
Serial.print(" to LED V1 and ");
Serial.print(ledV1State);
Serial.println(" to LED R1 ...");
digitalWrite(ledV1, !ledV1State);
digitalWrite(ledR1, ledV1State);
// Update Button Widget
Serial.print("Location E, writing ");
Serial.print(relais1Sate);
Serial.println(" to Button Widget on pin V1 ...");
Blynk.virtualWrite(V1, relais1Sate);
btn1State = LOW;
}
}
else
{
btn1State = HIGH;
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V1);
}
void checkPhysicalButton1();
void setup()
{
WiFi.begin(ssid, pass);
Blynk.config(auth);
// Debug console
Serial.begin(9600);
pinMode(relais1, OUTPUT);
pinMode(btn1, INPUT_PULLUP);
digitalWrite(relais1, relais1Sate);
pinMode(ledV1, OUTPUT);
pinMode(ledR1, OUTPUT);
timer.setInterval(100L, checkPhysicalButton1);
}
void loop()
{
Blynk.run();
timer.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
Widget buton : OFF
13:01:04.878 -> [135] Connecting to blynk-cloud.com:80
13:01:09.897 -> [5136] Connecting to blynk-cloud.com:80
13:01:10.302 -> [5564] Ready (ping: 307ms).
13:01:10.915 -> Widget Button V1 changed. Writing 0 to Relay 1 and LED V1, and 1 to LED R1 ...
13:01:16.684 -> Location A, btn1 = 0 btn1State = 1
13:01:16.718 -> Location B, btn1 = 27, btn1State = 1
13:01:16.751 -> Location C, writing 1 to Relay 1 ...
13:01:16.784 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
13:01:16.853 -> Location E, writing 1 to Button Widget on pin V1 ...
13:01:16.922 -> Location A, btn1 = 0 btn1State = 0
13:01:20.467 -> Location A, btn1 = 0 btn1State = 1
13:01:20.500 -> Location B, btn1 = 27, btn1State = 1
13:01:20.568 -> Location C, writing 0 to Relay 1 ...
13:01:20.602 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
13:01:20.636 -> Location E, writing 0 to Button Widget on pin V1 ...
13:01:20.704 -> Location A, btn1 = 0 btn1State = 0
13:01:23.164 -> Location A, btn1 = 0 btn1State = 1
13:01:23.233 -> Location B, btn1 = 27, btn1State = 1
13:01:23.266 -> Location C, writing 1 to Relay 1 ...
13:01:23.300 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
13:01:23.335 -> Location E, writing 1 to Button Widget on pin V1 ...
13:01:23.405 -> Location A, btn1 = 0 btn1State = 0
13:01:24.664 -> Location A, btn1 = 0 btn1State = 1
13:01:24.732 -> Location B, btn1 = 27, btn1State = 1
13:01:24.766 -> Location C, writing 0 to Relay 1 ...
13:01:24.800 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
13:01:24.835 -> Location E, writing 0 to Button Widget on pin V1 ...
13:01:24.904 -> Location A, btn1 = 0 btn1State = 0
Widget bouton ON
13:04:18.557 -> [135] Connecting to blynk-cloud.com:80
13:04:23.576 -> [5136] Connecting to blynk-cloud.com:80
13:04:24.152 -> [5715] Ready (ping: 306ms).
13:04:24.764 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
13:04:36.082 -> Location A, btn1 = 0 btn1State = 1
13:04:36.117 -> Location B, btn1 = 27, btn1State = 1
13:04:36.150 -> Location C, writing 0 to Relay 1 ...
13:04:36.184 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
13:04:36.252 -> Location E, writing 0 to Button Widget on pin V1 ...
13:04:36.286 -> Location A, btn1 = 0 btn1State = 0
13:04:38.362 -> Location A, btn1 = 0 btn1State = 1
13:04:38.395 -> Location B, btn1 = 27, btn1State = 1
13:04:38.429 -> Location C, writing 1 to Relay 1 ...
13:04:38.497 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
13:04:38.531 -> Location E, writing 1 to Button Widget on pin V1 ...
13:04:38.600 -> Location A, btn1 = 0 btn1State = 0
13:04:39.968 -> Location A, btn1 = 0 btn1State = 1
13:04:40.001 -> Location B, btn1 = 27, btn1State = 1
13:04:40.035 -> Location C, writing 0 to Relay 1 ...
13:04:40.069 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
13:04:40.138 -> Location E, writing 0 to Button Widget on pin V1 ...
13:04:41.470 -> Location A, btn1 = 0 btn1State = 1
13:04:41.503 -> Location B, btn1 = 27, btn1State = 1
13:04:41.536 -> Location C, writing 1 to Relay 1 ...
13:04:41.570 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
13:04:41.638 -> Location E, writing 1 to Button Widget on pin V1 ...
13:04:41.707 -> Location A, btn1 = 1 btn1State = 0