help switch button

please im working on a project covid: when button pressed led on for 2 second then led off even button still pressed

thanks

You need to detect the moment (the event) that a button was pressed. The State-Change-Detection shows how to do that: https://www.arduino.cc/en/Tutorial/StateChangeDetection.

You might also have to debounce the button.

The Bounce2 library can debounce a button and can also detect the moment that a button was pressed.

Have you used a timer with millis() before ? You need the Blink-Without-Delay if you want to do other things while the led is on: https://www.arduino.cc/en/tutorial/BlinkWithoutDelay.

When you don't have to do other things while the led is on, then you can use a delay of 2 seconds.