-
Serial.available() returns the number of characters already in the serial input buffer. It doesn't wait for characters to arrive on the serial interface or anything like that.
-
The Serial.flush() is completely unnecessary. It waits till all characters in the outgoing buffer are sent. As you haven't sent anything, it does nothing.
-
Don't use a delay() if it's not necessary.
-
Don't use the String class, it clobbers your memory and the current IDE has a bug that produces a memory leak.