Go Down

Topic: while () as wait (Read 795 times) previous topic - next topic

fuzzball27

Hi all,
I'm using the "while ()" function as a sort of wait function for my buttons:
Code: [Select]
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?
fuzzball27 >>-->

Bobnova

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

bilbo

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...
Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?"
The cat asked, "Where do you want to go?"
"I don't know," Ali

fuzzball27

fuzzball27 >>-->

robtillaart


Shorter:
- leave out the delay(1); why wait ?
- HIGH == 1 == TRUE

==>

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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Go Up