I wrote data from physical pin to virtual pin.
When pressed button state of virtual pin V0 on App changed, but on device couldnt sync that data.
Please help me this case.
Thanks
#include "header.h"
#include "BlynkEdgent.h"
BlynkTimer timer;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0); // get the latest value
}
// When App button is pushed - switch the state
BLYNK_WRITE(V0) {
ledState = param.asInt();
digitalWrite(ledPin, ledState);
}
void setup()
{
Serial.begin(115200);
delay(100);
pinMode(button, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
//Connecting to Blynk Cloud
Blynk.begin(auth, ssid, pass);
timer.setInterval(100L, readInput);
Serial.println("Connected!");
}
void loop() {
Blynk.run();
timer.run();
}
void readInput() {
if (digitalRead(button) == ON) {
// btn1State is used to avoid sequential toggles
if (changed == OFF) {
// Toggle LED state
ledState = !ledState;
Blynk.virtualWrite(V0, ledState);
}
changed = ON;
} else {
changed = OFF;
}
}