Blynk Button State - Force Reset from hardware code(Arduino UNO)?

Hello everyone,
I’m a new to Arduino and Blynk fan, have just recently started fooling around with these toys. I have this little project I’ve been working on that’s giving me a bit of trouble with fine tuning.

I am using a Arduino UNO and Blynk App, no other external hardware, and am hoping to build a simple visual display built with multiple LED Widgets, controlled by 4 Buttons(Widgets).
I’ve got the LEDs lighting up in the proper sequence, and a red square representing “stop” once the LED sequence is done processing. I have the App setup as 2 Tabs, one for the controller Buttons and the other for LED display to be used by a second user. On the controller Tab I also included a “always on” LED that I toggle RED or GREEN depending if Tab 1 is displaying activity or if it’s on standby, that works well.

Up to there it was going really well. lol

Where I’ve encountered an issue is with the 4 V Pin Buttons from my Control Tab, it seems like they work once from the first press, but once the activity is done and the “Activity LED” is updated back to GREEN, I need to press the buttons twice or often three times for the activity to repeat itself.

I feel like the V Pin Buttons are not reset to 0, I tried Push and Switch by the way with no difference, so I tried resetting their state via the hardware, with Blynk.virtualWrite(V0, LOW) for example, but that doesn’t seem to help.

Upon a Button press, the first time it works for example, I do this :

    BLYNK_WRITE(V0){
          int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
          if (pinValue == 1){
          acty_on();
          stop_off();
          for (int x=0;x < 8;x++)      {
          Blynk.virtualWrite(V16, 1023);      Blynk.virtualWrite(V17, 1023);      Blynk.virtualWrite(V18, 1023);
          Blynk.virtualWrite(V24, 1023);      Blynk.virtualWrite(V14, 1023);      Blynk.virtualWrite(V19, 1023);      Blynk.virtualWrite(V6, 1023);
          Blynk.virtualWrite(V16, 0);      Blynk.virtualWrite(V17, 0);      Blynk.virtualWrite(V18, 0);
          Blynk.virtualWrite(V24, 0);      Blynk.virtualWrite(V14, 0);      Blynk.virtualWrite(V19, 0);      Blynk.virtualWrite(V6, 0);
          }
          stop_on();
          acty_off();
          }
          Blynk.virtualWrite(V0, LOW);
    }

please post your full code, not just a part of it. otherwise we can’t help.

@wanek, no access to the code now but will post asap!
Thanks

Probably not the source of the issue, but use numbers… just as you have with all others. AKA Blynk.virtualWrite(V0, 0);

here is the entire code @wanek, thank you @Gunner, will change those tonight!

    //#define BLYNK_PRINT DebugSerial
    #define BLYNK_RED "#D3435C"
    #define BLYNK_GREEN "#23C48E"

    #include <SoftwareSerial.h>
    //SoftwareSerial DebugSerial(2, 3); // RX, TX

    #include <BlynkSimpleStream.h>

    char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

    WidgetLED led11(V11);WidgetLED led12(V12);WidgetLED led13(V13);
WidgetLED led16(V16);WidgetLED led17(V17);    WidgetLED led18(V18);
WidgetLED led21(V21);WidgetLED led22(V22);WidgetLED led23(V23);

    WidgetLED led29(V29);  // LED that's on Control Tab, displays Activity Status Green or Red

    void acty_on(){
      Blynk.setProperty(V29, "color", BLYNK_RED);led29.on();  // Activity Status Red On while working
    }

    void acty_off(){
      Blynk.setProperty(V29, "color", BLYNK_GREEN);led29.on();  // Activity Status Green On while on Standby
    }

    // Draw Red square while on Standby
    void stop_on(){
      Blynk.setProperty(V11, "color", BLYNK_RED);led11.on();  Blynk.setProperty(V12, "color", BLYNK_RED);led12.on();
      Blynk.setProperty(V13, "color", BLYNK_RED);led13.on();  Blynk.setProperty(V16, "color", BLYNK_RED);led16.on();
      Blynk.setProperty(V17, "color", BLYNK_RED);led17.on();  Blynk.setProperty(V18, "color", BLYNK_RED);led18.on();
      Blynk.setProperty(V21, "color", BLYNK_RED);led21.on();  Blynk.setProperty(V22, "color", BLYNK_RED);led22.on();
      Blynk.setProperty(V23, "color", BLYNK_RED);led23.on();
    }

    // Erase Red square before Drawing arrows 
    void stop_off(){
      Blynk.setProperty(V11, "color", BLYNK_GREEN);led11.off();  Blynk.setProperty(V12, "color", BLYNK_GREEN);led12.off();
      Blynk.setProperty(V13, "color", BLYNK_GREEN);led13.off();  Blynk.setProperty(V16, "color", BLYNK_GREEN);led16.off();
      Blynk.setProperty(V17, "color", BLYNK_GREEN);led17.off();  Blynk.setProperty(V18, "color", BLYNK_GREEN);led18.off();
      Blynk.setProperty(V21, "color", BLYNK_GREEN);led21.off();  Blynk.setProperty(V22, "color", BLYNK_GREEN);led22.off();
      Blynk.setProperty(V23, "color", BLYNK_GREEN);led23.off();
    }

    // Draw Arrows pointing Down
    BLYNK_WRITE(V31){
          int pinValue = param.asInt(); // assigning incoming value from pin V31 to a variable
          if (pinValue == 1){
          acty_on();
          stop_off();
          for (int x=0;x < 8;x++)      {
          Blynk.virtualWrite(V12, 1023);      Blynk.virtualWrite(V17, 1023);      Blynk.virtualWrite(V22, 1023);
          Blynk.virtualWrite(V27, 1023);      Blynk.virtualWrite(V25, 1023);      Blynk.virtualWrite(V26, 1023);      Blynk.virtualWrite(V5, 1023);
          Blynk.virtualWrite(V12, 0);      Blynk.virtualWrite(V17, 0);      Blynk.virtualWrite(V22, 0);
          Blynk.virtualWrite(V27, 0);      Blynk.virtualWrite(V25, 0);      Blynk.virtualWrite(V26, 0);      Blynk.virtualWrite(V5, 0);
          }
          stop_on();
          acty_off();
          }
          Blynk.virtualWrite(V31, LOW);
    }

    // Draw Arrows pointing Up
    BLYNK_WRITE(V2){
          int pinValue = param.asInt(); // assigning incoming value from pin V2 to a variable
          if (pinValue == 1){
          acty_on();
          stop_off();
          for (int x=0;x < 8;x++)      {
          Blynk.virtualWrite(V22, 1023);      Blynk.virtualWrite(V17, 1023);      Blynk.virtualWrite(V12, 1023);
          Blynk.virtualWrite(V7, 1023);      Blynk.virtualWrite(V9, 1023);      Blynk.virtualWrite(V8, 1023);      Blynk.virtualWrite(V3, 1023);
          Blynk.virtualWrite(V22, 0);      Blynk.virtualWrite(V17, 0);      Blynk.virtualWrite(V12, 0);
          Blynk.virtualWrite(V7, 0);      Blynk.virtualWrite(V9, 0);      Blynk.virtualWrite(V8, 0);      Blynk.virtualWrite(V3, 0);
          }
          stop_on();
          acty_off();
          }
          Blynk.virtualWrite(V2, LOW);
    }

    // Draw Arrows pointing Left
    BLYNK_WRITE(V30){
          int pinValue = param.asInt(); // assigning incoming value from pin V30 to a variable
          if (pinValue == 1){
          acty_on();
          stop_off();
          for (int x=0;x < 8;x++)      {
          Blynk.virtualWrite(V18, 1023);      Blynk.virtualWrite(V17, 1023);      Blynk.virtualWrite(V16, 1023);
          Blynk.virtualWrite(V10, 1023);      Blynk.virtualWrite(V20, 1023);      Blynk.virtualWrite(V15, 1023);      Blynk.virtualWrite(V4, 1023);
          Blynk.virtualWrite(V18, 0);      Blynk.virtualWrite(V17, 0);      Blynk.virtualWrite(V16, 0);
          Blynk.virtualWrite(V10, 0);      Blynk.virtualWrite(V20, 0);      Blynk.virtualWrite(V15, 0);      Blynk.virtualWrite(V4, 0);
          }
          stop_on();
          acty_off();
          }
          Blynk.virtualWrite(V30, LOW);
    }

    //Draw Arrows pointing Right
    BLYNK_WRITE(V0){
          int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
          if (pinValue == 1){
          acty_on();
          stop_off();
          for (int x=0;x < 8;x++)      {
          Blynk.virtualWrite(V16, 1023);      Blynk.virtualWrite(V17, 1023);      Blynk.virtualWrite(V18, 1023);
          Blynk.virtualWrite(V24, 1023);      Blynk.virtualWrite(V14, 1023);      Blynk.virtualWrite(V19, 1023);      Blynk.virtualWrite(V6, 1023);
          Blynk.virtualWrite(V16, 0);      Blynk.virtualWrite(V17, 0);      Blynk.virtualWrite(V18, 0);
          Blynk.virtualWrite(V24, 0);      Blynk.virtualWrite(V14, 0);      Blynk.virtualWrite(V19, 0);      Blynk.virtualWrite(V6, 0);
          }
          stop_on();
          acty_off();
          }
          Blynk.virtualWrite(V0, LOW);
    }
    void setup(){
      //DebugSerial.begin(9600);
      Serial.begin(115200);
      Blynk.begin(Serial, auth);
    }

    // This should execute upon connecting to Blynk server
    BLYNK_CONNECTED(){
      stop_on();    // Display Red Stop square upon App Open
      acty_off();
      Blynk.virtualWrite(V0, LOW);
      Blynk.virtualWrite(V2, LOW);
      Blynk.virtualWrite(V30, LOW);
      Blynk.virtualWrite(V31, LOW);
    }

    void loop(){
      Blynk.run();
    }

Thanks for the input you guys!

Hi everyone,
No other ideas, I’ve done the one recommended code change but that did not help. I’m still seeing the action for a given virtual button get done right away on the first click but then it takes 2 or 3 clicks of the same virtual button to get the same execution of code to happen.
Any recommendations would be appreciated.
TY

I don’t have the resources to work on my own projects and others… so i have not read through your code…

But I can say that everytime you “click” on a Button Widget you get two actions, ON and OFF… and if you do not have some form of timing control, like flags and flag monitoring code, then each time you click, your BLYNK_WRITE() function tries to run… and if it hasn’t finished the ‘first time’ when you press it again, then it starts nesting actions, and basically gets confused.

image

1 Like

Thanks gunner, I’ll research flags and timers.