The Arduino IDE example sketch
File > Examples > 02. Digital > StateChangeDetection
should get you on the right path. Figure out what states you want (maybe just two in general: LEDs off and timed LED routines) then create a variable such as a byte, where byte controlByte = 0; is the do nothing at all state, then detect the state change of the pushbutton to increment the state to say, 1, which calls the LED routine, then detect the next state change of the pushbutton that sets controlByte back to zero, or whatever you like, such as setting the state of controlByte to one but only for 10 seconds, then back to zero after the timer runs out, as others have mentioned.
Consider the following sketch, no hardware required. Just set Serial Monitor to 115200 baud.
Thanks again to forum member @cattledog who posted the countdown thing I couldn't wrap my head around for ages and now refer to often. I think it's similar to what you're after. OG assistance repackaged to help some other forum member, IIRC, and I saved it so here it is. Hope it helps.
/* FINALLY! a dude that gets it. Not the same toggle the light forever thang.
credit whare it's due, cattledog
https://forum.arduino.cc/t/countdown-timer-without-delay/680769
*/
const int ledPin = LED_BUILTIN; // the number of the LED pin
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000; // interval at which to blink (milliseconds)
int timer = 10; // Set the timer to 10 seconds
boolean bombArmed;
boolean gotTheMessage;
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
digitalWrite(ledPin, LOW);
bombArmed = false;
gotTheMessage = false;
Serial.println("\nArm bomb by typing a. Disarm by typing d.");
Serial.println("Typing r resets clock to 10 seconds.\n");
}
void loop() {
if (Serial.available() > 0) {
char setBomb = Serial.read();
switch (setBomb) {
case 'a':
if (gotTheMessage == false) {
Serial.println("\nBomb is armed - do something!\n");
delay(1000);
gotTheMessage = true;
}
bombArmed = true;
break;
case 'd':
bombArmed = false;
Serial.println("\ndisarmed");
break;
case 'r':
Serial.println("\nreset clock");
timer = 10;
break;
}
}
if (bombArmed == true) {
theFinalCountdown();
}
digitalWrite(ledPin, LOW);
}
void theFinalCountdown() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
digitalWrite(ledPin, HIGH);
previousMillis = currentMillis;
Serial.println(timer);
timer--; //decrease timer count
if (timer < 0) {
Serial.println("\nBOOM!");
digitalWrite(ledPin, HIGH);
//while (true); // uncomment for one shot action
while (millis() < previousMillis + (interval * 5)) {
// do a whole lotta nothin'
}
timer = 10;
bombArmed = false;
gotTheMessage = false;
}
}
}