condition = true but do...while loop does not end

I'm puzzles why the do...while loop does not end while the condition (0) is met. The slave i read the status of gives a 0 in return (tested this with output to monitor). Why?

 do {
    Wire.requestFrom(1, 1);    
    while (Wire.available()) { 
      int status_slave = Wire.read(); 
    }
  } while (status_slave != 0) ;

Hi
Does the whole code compile?

You have declared the variable
int status_slave inside { },
so it is local to the code inside the { }

but you are using it outside the { } in the while command.

I think you should be declaring status_slave as a global variable.

Tom... :slight_smile:

Also, does the slave give the numeric value 0 (0b00000000) or the character '0' (0b00110000)

And you should put a Serial.print() in the code to show you what is actually received - maybe the 0 (or '0') is not being received.

...R

Thx TomGeorge. Stupdid mistake i didn't spot. I had declared the variable in the setup, but did it again in inside the inner while loop. That made it not function. Problem solved! Thx a lot!

TomGeorge:
Hi
Does the whole code compile?

You have declared the variable
int status_slave inside { },
so it is local to the code inside the { }

but you are using it outside the { } in the while command.

I think you should be declaring status_slave as a global variable.

Tom... :slight_smile: