// code uses a single if (Serial.available()>0) {...}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
Serial.print("buffer empty: ");
Serial.println(Serial.read()); // buffer empty - prints -1
}
void loop() {
if (Serial.available() > 0) {
char ch = Serial.read(); // ch only available in if statement
Serial.print("Received ");
Serial.write(ch);
Serial.print(" which is ");
Serial.println(ch, DEC);
}
delay(1000);
}