Serial.read() is non blocking. if byte is not available the it returns -1 (that is why the return type is int).
so you must check if the returned value isn't -1 or check if data are available before read.
Serial.read() is non blocking. if byte is not available the it returns -1 (that is why the return type is int).
so you must check if the returned value isn't -1 or check if data are available before read.