Update digital pin status in app

Hi,
I’ve created a simple project to control my rgb led strip.
I’ve added 3 buttons into app D5, D2, D8 as switches to control pins on or off and that works perfectly.
Now I wanted to create a virtual pin to control all on or all off. I’ve created v0 and v1 respectivly as a buttons. Below is the code I use.

BLYNK_WRITE(V0) 
{
  int pinValue0 = param.asInt();
 if (pinValue0==1){
    digitalWrite(D2, 0);
    digitalWrite(D5, 0);
    digitalWrite(D8, 0);
 }
}

BLYNK_WRITE(V1) 
{
  int pinValue1 = param.asInt();
 if (pinValue1==1){
    digitalWrite(D2, 1);
    digitalWrite(D5, 1);
    digitalWrite(D8, 1);
    }
}

And it does the job as leds are turned off and on but the coresponding buttons assigned for D2,D5and D8 do not update theyre state in the app.
How to sync those statuses? For example if I enable pin D8 in the app it says on but when I tap on V0 button for all off leds turn off but button D8 in app stays on.

You could just use ONE button widget, set to switch mode, then you have your logical ON for RGB ON and OFF for RGB OFF

BLYNK_WRITE(V0)
{
  int pinValue0 = param.asInt();
  if (pinValue0 == 1) {
    digitalWrite(D2, 1);
    digitalWrite(D5, 1);
    digitalWrite(D8, 1);
  } else {
    digitalWrite(D2, 0);
    digitalWrite(D5, 0);
    digitalWrite(D8, 0);
  }
}

True but this still leaves additional 3 buttons for individual collors that are not updated and when I turn all off buttons that were on appear to be still on even when LED’s actually turned off ;]


This is how my app look now. And the separate green, red, blue stay on when V0 is pressed and tu turn LED’s on again I have tap on them to change them to off and then again to turn on.

D5,D2,D8 are set as switches and V0,V1 are buttons.

I think I read yesterday that only Virtual pins are synched back to the app, but I cant find it again.
If that is the case, I think you need to set all RGB switches to use virtual pins, and then update the virtual pins when V0 and V1 are changed. When the RGB virtuals are changed you do the actual digitalWrite operations to the physical outputs.

If this is not the case, I do apologize in advance.

Simply switch to using virtual pins for all your button widgets.

Pete.

Yep that solved the issue nicely :slight_smile: Thanks

1 Like