Hello, I am having trouble understanding this example (HardwareSyncStateFromApp).
You can synchronize the state of widgets with hardware states,
even if hardware resets or looses connection temporarily
Project setup in the Blynk app:
Slider widget (0...100) on V0
Slider widget (0...100) on V2
Button widget on digital pin (connected to an LED)
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect) {
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
// You can also update individual virtual pins like this:
//Blynk.syncVirtual(V0, V1, V4);
isFirstConnect = false;
}
// Let's write your hardware uptime to Virtual Pin 2
int value = millis() / 1000;
Blynk.virtualWrite(V2, value);
}
BLYNK_WRITE(V0)
{
int value = param.asInt();
Blynk.virtualWrite(V2, value);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}
So I understand that Blynk.syncall() is supposed to call Blynk__Write function for ALL virtual pins. However in the example only BLYNK_WRITE(V0) is defined. So my question is shouldn’t BLYNK_WRITE(V2) also be in the code? Why only BLYNK_WRITE(V0) is defined? Am I misunderstanding the meaning of this example? Can you tell me what this example does.
Thanks!