while () as wait

Hi all,
I'm using the "while ()" function as a sort of wait function for my buttons:

 while (digitalRead(button1) == HIGH || digitalRead(button2) == HIGH || digitalRead(button3) == HIGH || digitalRead(button4) == HIGH) {
       delay(1);
     }

Unfortunately, the user is required to press all four buttons simultaneously to "shut off" the "wait" function. I only want the requirement to be one button. How might I do this?

Change the || (or) to && (and).

If this is really the way you want to accomplish it, change the logic ORs ( || ) to logic ANDs ( && ) . This will execute the while loop while all of the pins tested are high, but if one of them goes low, it will break. Keep in mind that while waiting with delay, the processor cannot do anything, as this may be a problem later on in development.

Edit: Bobnova got it first. Stupid iphone...

Thank you guys!

Shorter:

  • leave out the delay(1); why wait ?
  • HIGH == 1 == TRUE

==>

while (digitalRead(button1) && digitalRead(button2) && digitalRead(button3) && digitalRead(button4) ) ;

Use And!! That is '&&' instead of ||.