BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Annoying inconvenience with Buttons


#1

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.


#2

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


#3

urgh…you’re completely right, my bad.


#4
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
  }
}

#5

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