You want the microcontroller do what most microcontroller-applications do.
Running multiple tasks so fast sequentially that the user-experience is the tasks are done in parallel.
This requires quit some learning that goes beyond a simple blink or receive some bytes.
Doing multiple things in sequential requieres on big loop where each task takes over "control" for a very short time does a single step and then hands over "control" to the next task.
Well it is not really taking "control" it is a jump in / jump out in each task.
This is done by calling each function inside the main-loop which is
void loop() {
}
itself
one task is checking if a new command is in the receive-buffer
with a very important difference:
the looping is done by void-loop and not inside your "receive-code"
one task does the blink etc.
non-blocking timing is done based on function millis()
So one part is learing what is a function
One part is learn to "loop" with repeated calling of functions
One part is learning to use non-blocking timing based on function millis()
Take a look into this tutorial:
It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.
best regards Stefan
