Hello
I think the IDE example named BlinkWithOutDelay will help.
https://www.arduino.cc/en/pmwiki.php?n=Tutorial/BlinkWithoutDelay#:~:text=Blink%20Without%20Delay.%20Sometimes%20you%20need%20to%20do,pass%2C%20your%20program%20will%20miss%20the%20button%20press.