Hello I created a sketch on arduino with a button “turn it all off” then pressing the d7 button go off d2-d3 etc …, now the problem is that if I turn off the buttons that are turned on via the “Shutdown all”
"they really turn off but they always stay ON in the app blynk, the buttons are all synchronized the state of widgets with hardware states,
even if hardware resets or looses connection temporarily lost the connection, in another test I created the virtual pin and it works perfectly only that I can not synchronize the graphic buttons that remain ON and not change status if pressed by the button, “turn all off”
The best way to do this is to use the wonderful thing called Virtual pins. The state of the virtual pins are maintained in the server and the app can sync with that. Not so for physical pins.
// let us set up virtual pins V2 and V3 Giving example for 1 pin.Let shutall be on V0
//The widget should be linked to V2 and V3
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin V2 to a variable
digitalWrite(pin2, pinValue);
digitalWrite(pin3, pinValue);
Blynk.virtualWrite(V2, pinValue);
Blynk.virtualWrite(V3, pinValue);
}
BLYNK_WRITE(V2)
{
int pinValue = param.asInt(); // assigning incoming value from pin V2 to a variable
digitalWrite(pin2, pinValue);
}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
digitalWrite(pin3, pinValue);
}
void pulsante()
{
stato_pulsante = digitalRead(pulsante);
if (stato_pulsante == HIGH) {
Blynk.virtualWrite(V2, HIGH);
Blynk.virtualWrite(V3, HIGH);
}
}
void setup() {
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pulsante, INPUT);
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(Serial, auth);
SwSerial.begin(9600);
timer.setInterval(1000L, pulsante);
}
void loop() {
Blynk.run();
timer.run();
}
Lessons from @Costas, @Gunner and @PeteKnight - keep loop simple and minimal. Set up periodic activity by timers. In my sketch, I’ve used V0 for shutall.In that, apart from pulling down the pins, you will need to do a Blynk.virtualWrite() for V2 and V3 with the HIGH/LOW value so that the app also shows the state properly.
Suggest you look at BLYNK_CONNECTED() call to sync all virtual pins using the Blynk.sync() or Blynk.syncAll() calls. Will help carry states across reboots.