Waiting for a button press

Hey guys,

I am using the following code to wait for a button press to start,

  while(true){
    if (digitalRead(BUTTON_PIN) == LOW)
      break;

But sometimes I have to press the button multiple times for arduino to detect press sometimes it works with one press, am I missing something?

Button is on the prototyping board(JC1) by default it is high.

Did you set BUTTON_PIN as INPUT?

do:
while (digitalRead(BUTTON_PIN));

yeap BUTTON_PIN is set as INPUT.

while (digitalRead(BUTTON_PIN));

that solved the issue..

Thanks.

How about:

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

Basically, while the button is not pressed, do nothing (nothing inside the brackets)

Mowcius

How about posting your full code? This way we can get a better idea of what your trying to accomplish. It just seams like your trying to over complicate this.