Sketch: am I getting it?

What you have described is best dealt with using a thing called a finite state machine. There are tutorials and examples on FSMs, here are some of them:

Using millis for timing
Demonstration for several things at the same time

As to taking things out of the loop() function, yes, take everything out. Ideally split your code into separate functions that each does a defined thing, then the only thing in your loop function should be calls to the individual functions. If you do that then the code is a lot easier to read and debug.

As to the words 'finite state machine', which might have you a little worried, consider a restaurant:

You wouldn’t expect this when you go into a restaurant:
A waiter meets you at the door, takes you to a table, gives you a menu then waits by your table while you decide what to order. The waiter takes your order, goes to the kitchen and waits there while the chef cooks your food. However, as the staff in this restaurant only ever deal with one customer at a time your waiter has to wait with other waiters while the chef cooks 5 other meals before starting on yours. When the food is eventually ready the waiter brings it to your table then waits by your table while you eat it. When you’ve finished eating the waiter takes your plates away and returns to ask if you want anything else. This continues until you leave. No one else gets served.
I’m not going to describe what really happens in a restaurant as you already know. A waiter uses exactly the same system as a state machine to serve people when they need serving and check to see who needs serving next between dealing with customers. You can build functions for the different tasks a waiter does such as:

void takeOrder();
void bringFoodToTable();

You call these from loop(); While in loop the waiter checks to see if any tables need attention, and if they do s/he goes to find out what they need. If not, then s/he keeps checking until someone needs something. Computer code should be written along the same principals.

A restaurant, indeed many ordinary things in life, operate as a finite state machine, it's just no one calles it that. Finite state machine in normal life is called 'multi-tasking', and you will be familiar with the debates over whether men or women are best at it. Well, regardless of the debate that's what you are aiming for, just on a different scale.

Good luck with your project.

1 Like