You need non blocking code, read about “state machines” - there are plenty of tutorials on line, here is one of the highest hits or this one when googling for “arduino state machines tutorial”. You’ll find also videos if you are more of a visual learner than a reader