while(....) terminating unexpectedly

Can't understand this.....

I have a while(..expression...) loop that seems to ignore part of the expression evaluation.

It's an MP3 player application that I have attempted to include a "mute" feature.

I need to terminate the "while" for several reasons...

current track has finished (MP3_Ready input goes "true"). keypad "Next Track" button pressed. keypad "Prev Track" button pressed. system mode change.

I certainly don't want the "while" to terminate if "muted".

Everything works perfectly, except this "mute" feature, and I cannot understand why....

Here's the while loop....

// wait mode change, or track finished, or "Next Track", or "Previous Track" while(!muted && !digitalRead(MP3_Ready) && settings.currentMode == settings.lastMode && !MP3_Next && !MP3_Prev) { char key = keypad.getKey(); updateLEDs(); delay(100); }

Bear in mind that the boolean tag "muted" is toggled in keypad.getkey();

case PRESSED: if (key == '*') { muted = !muted;

... and I've added a debugging Serial.print(muted); after the while loop. I can clearly see that the while is terminating with muted = 1, and I simply cannot see how that while loop is terminating with muted = 1

I don't believe there to be a limit to the size or complexity of the expression evaluated in a "while(....)", doesn't seem to be overkill to me.

Any thoughts anyone, pulling what hair I have left out on this....

please post ALL your code.

Grumpy_Mike: please post ALL your code.

Sent a PM Mike

    // wait mode change, or track finished, or "Next Track", or "Previous Track"
    while(!muted && ...a bunch of other stuff..) {
    }

 I simply cannot see how that while loop is terminating with muted = 1

1 != 0, therefore 1 evaluates to true. !true evaluates to false and anything ANDed with false is also false. That terminates the loop.

johnwasser: ```     // wait mode change, or track finished, or "Next Track", or "Previous Track"     while(!muted && ...a bunch of other stuff..) {     }

I simply cannot see how that while loop is terminating with muted = 1





1 != 0, therefore 1 evaluates to true. !true evaluates to false and anything ANDed with false is also false. That terminates the loop.

dammit !! I teach PLC's how come I didn't see the woods from the trees...

Changed... while(!muted && !digitalRead(MP3_Ready) && settings.currentMode == settings.lastMode && !MP3_Next && !MP3_Prev)

to..

while(muted || !digitalRead(MP3_Ready) && settings.currentMode == settings.lastMode && !MP3_Next && !MP3_Prev)

and of course it cured it...

thanks johnwasser for clearing my head, that completes my project code, as I said everything else worked flawlessly, just this logic puzzle got me !!!