what does Serial.flush() do

i was wondering what Serial.flush() do . i tried understanding from the arduino's official site but i could not undertstand anything. can anyone help?

Hmmm.

Waits for the transmission of outgoing serial data to complete.

If you send a character, it is placed in a buffer for transmission. It takes time for each character to be sent because serial is slow. Once it is in the buffer, it will be sent automatically in the background while the program immediately moves on to the next statement. This is done so the program won't waste time waiting for characters to be sent.

flush() is a way to wait for it to be sent, instead of immediately moving on in the user program.

So after calling flush() you can be sure that all data has been sent, and the buffer is empty.

So after calling flush() you can be sure that all data has been sent, and the buffer is empty.

You can be sure the last character has been written to the UART transmit register, but you would be ill-advised to cut the power as soon as flush () returns.

AWOL:
You can be sure the last character has been written to the UART transmit register, but you would be ill-advised to cut the power as soon as flush () returns.

Current versions actually clear and check the TXC0 flag to see that the transmitter has finished sending so this should be safe.