What happens if you remove:
while(!Serial);
Serial.flush();
You say this is an Uno, though - so neither of those should be having any effect.
What happens if you remove:
while(!Serial);
Serial.flush();
You say this is an Uno, though - so neither of those should be having any effect.