Reading and writing of serial data are separate functions. When you .write() you just append the data to the TX buffer. When you .read() you just take the next character from the RX buffer.
All actual sending and receiving, and filling/emptying of the buffers is done inside the ISRs for the UART module.
That said, you really shouldn't use Serial inside an ...
How can one explain that using this code I get this toggle frequency on the digital pin ?
Code takes time to execute. Your ISR, when compiled, looks like:
124: 1f 92 push r1
126: 0f 92 push r0
128: 0f b6 in r0, 0x3f ; 63
12a: 0f 92 push r0
12c: 11 24 eor ...
Generally, if you want to find identifiers in your Arduino board support, you can run the ctags program on the libc and Arduino core files. ctags is used as part of the build process in its effort to generate C++ declarations for you. So it is generally available to you as an Arduino user. You should find ctags or ctags.exe in:
Make a statemachine.
Take a piece of paper and draw out the order of operation and each time you are waiting you specify what each button will do.
So for example each time button 1 is pushed you increment the counter and change the display.
When waiting for a timeout you check if(startTimestamp - millis() > timeout) for the next step.
Then give each ...