ARDUINO UNO nested loops

Hi there. i'm using arduino uno and i found that the code below does not work. Seems like "if" do not work inside "if" statements. how do i solve this problem dear community. if(ButtonStateAUTO==HIGH) { while(1) { Serial.println("auto"); delay(1); if(ButtonStateON1==HIGH) //while(1) { Serial.println("autoON1"); delay(1);} } } else if(ButtonStateMAN==HIGH) { //lcd.clear(); while(1) { Serial.println("man"); delay(1); if(ButtonStateON2==HIGH) Serial.println("manuALon2"); delay(1); } }

"if" statements can be nested with impunity. There is something wrong with your code

gmoon3 years ago

First off, you should explain to us what you're trying to achieve.

Secondly, you've commented out a couple of the statements (while() and lcd.clear()), so it's rather difficult to expand the brackets to a readable state.

But from what I can see, there's nothing inside the while() loops to change the "ButtonState" variables (unless you're doing that from an interrupt). So the if() statements never change their results.

If you do change those variable in an interrupt, make sure the variables are global. But basically there's not enough info here to offer anything but a guess...

Those while() loops are all infinite, BTW.