Need help with task priority

Hi Guys,

I am new in Arduino so i need help.... I have a set up with 4 buttons to control 4 lights.

when Button 1 is pressed and released , light 1 goes ON and OFF after 5 sec, and the same thing for the rest.

But my struggle is when multiple buttons are pressed after another..., like if a button is pressed and while the respective light is ON another button is also pressed, i want the second light to wait for the previous light go OFF before it can turn ON and the same thing for the rest.

Please can some one assist...
Thanks in Advance

Remove the delay () statements from your code and replace them with millis(). See the “blink without delay “ example.