How to wait for a button press using button lib?

I am using arduino button library, Arduino Playground - Button Library . In my setup I would like to wait for a button press then continue to loop at the end of my setup function I have,

  while(button.isPressed() == false);

initialized with

Button button = Button(9,PULLUP);

But sometimes I have to press it multiple times for it recognize a button press. How do you guys wait for an button event?

Previously I was using

  while(digitalRead(BUTTON_PIN)){
    delay(100);
  }

but it had the same problem, since after multiple presses it works I am assuming problem is code related, button is on a protoshield.

while(digitalRead(button) == LOW){}

:slight_smile:

I presume that is what you were looking for! :wink:

Mowcius

But sometimes I have to press it multiple times for it recognize a button press. How do you guys wait for an button event?

That really sounds like a problem with your switch.

That really sounds like a problem with your switch.

that turned out to be the problem switched to a new button and everything works.