Go Down

Topic: while () as wait (Read 1 time) previous topic - next topic


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) {

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 >>-->


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...
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 >>-->


- 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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131