Annoying inconvenience with Buttons

This really took me a looong while to figure out. Im using styled (this also happens with regular buttons) buttons to increase/decrease values and every time I hit the button the value was not updated once but twice (in the blynk_write when a vsync was detected the value was in/decreased accordingly however blynk_write ALWAYS runs twice. Only if you change the button to a switch does it run once.
Perhaps this is intended but its really annoying trying to figure out why on earth the blynk_write routine runs twice.

Isn’t it run twice because of state changing? One for 0->1 and second (when released) from 1->0
Then it should be enough just to handle the Buttonstate property

1 Like

urgh…you’re completely right, my bad.

1 Like
BLYNK_WRITE(vPin)  // Virtual button state detection.
{
  int buttonState = param.asInt();
  if (buttonState == 1) {
    // Does something when button pressed
  } else if (buttonState == 0) {  // else if is optional
   // Does something when button released
  }
}

Thanks! I decided to just set the button a switch. That works as well. But its good to be complete on this forum