If this is useful for others, I have successfully used this code
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "sempak"; //insert here your token generated by Blynk
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "sempak";
char pass[] = "sempak";
const int led1 = 12;
const int led2 = 14;
BlynkTimer timer;
void checkPhysicalButton();
int led1state = LOW;
int led2state = LOW;
int buttonState = 0;
int buttonValue1;
int buttonValue2;
// Every time we connect to the cloud...
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V0);
Blynk.syncVirtual(V1);
// Alternatively, you could override server state using:
//Blynk.virtualWrite(V0, led1state);
//Blynk.virtualWrite(V1, led2state);
}
// When App button is pushed - switch the state
BLYNK_WRITE(V0) {
led1state = param.asInt();
digitalWrite(led1, led1state);
}
BLYNK_WRITE(V1) {
led2state = param.asInt();
digitalWrite(led2, led2state);
}
void checkPhysicalButton()
{
buttonValue1 = analogRead(A0);
buttonValue2 = analogRead(A0);
if (buttonValue1>=532 && buttonValue1<=545) {
// btnState is used to avoid sequential toggles
if (buttonState != 0) {
// Toggle LED state
led1state = !led1state;
digitalWrite(led1, led1state);
// Update Button Widget
Blynk.virtualWrite(V0, led1state);
}
buttonState = LOW;
}
else if (buttonValue2>=441 && buttonValue2<=498) {
// btnState is used to avoid sequential toggles
if (buttonState != 0) {
// Toggle LED state
led2state = !led2state;
digitalWrite(led2, led2state);
// Update Button Widget
Blynk.virtualWrite(V1, led2state);
}
buttonState = LOW;
} else {
buttonState = HIGH;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
// You can also specify server:
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
digitalWrite(led1, led1state);
digitalWrite(led2, led2state);
// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);
timer.setInterval(100L, []() { // Run every 100 milliseconds
Serial.println(analogRead(A0)); // Display the value
});
}
void loop()
{
Blynk.run();
timer.run();
}
