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


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