First code ever, trying to add some kind of inactivity timer reset

Hello,
I just write my first code ever for a small project I have, its sound basic but im lost right now and will need some help.

My goal is simple, its kind of a question True or False game, I have 6 question , 1 true and 1 false buttons. The user must press and hold one "question button" then press true or false, if the answer is right, 1 of the 6 led ( one by question) light up and stay light.

So far my code do exactly that... I know its crude and I should use array but its already a miracle that its working first time.

The problem is I dont know how to make the game reset when its done and also add a inactivity timer reset

When its done (6 led light up)the game should reset but lets some time to the user to see all the led light up say 5 second then start again.

Also when its resetting whatever inactivity or when its done after the 5 sec, I wonder if its hard to make it blink for like 3 sec ( not critical will just look cool).

Its possible that I add thing into my code that I dont need... I try to copy a couple of basic tutorial and some exemple I saw online , anyway here my code:

/*
Test on MEGA 2560, must be use on UNO later
 */
 const int buttonF = 30;      // button False , to replace by 14 (analog 0) with the Uno
 const int buttonT = 31;      // button True , to replace with 15(analog 1) with the Uno
 const int button1 = 2;      // button question 1
 const int button2 = 3;      // button question 2
 const int button3 = 4;      // button question 3
 const int button4 = 5;      // button question 4
 const int button5 = 6;      // button question 5
 const int button6 = 7;      // button question 6
 
 const int led1 = 13;
 const int led2 = 12;
 const int led3 = 11;
 const int led4 = 10;
 const int led5 = 9;
 const int led6 = 8;
 
 
 int buttonStateT = 0;
 int buttonStateF = 0;
 int buttonState1 = 0;
 int buttonState2 = 0;
 int buttonState3 = 0;
 int buttonState4 = 0;
 int buttonState5 = 0;
 int buttonState6 = 0;
 
 void setup(){
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(buttonF, INPUT);
  pinMode(buttonT, INPUT);
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
  pinMode(button5, INPUT);
  pinMode(button6, INPUT);

}
 
 void loop() {
   
  
  // check if the pushbutton is pressed.  
  buttonStateT = digitalRead(buttonT);  
  buttonStateF = digitalRead(buttonF); 
  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  buttonState3 = digitalRead(button3); 
  buttonState4 = digitalRead(button4);
  buttonState5 = digitalRead(button5);
  buttonState6 = digitalRead(button6);
  
 
  if (buttonState1 == HIGH && buttonStateT == HIGH) {     // If button1 and buttonT are pressed   
     digitalWrite(led1, HIGH);      // Light led1
  }
  
  if (buttonState2 == HIGH && buttonStateT == HIGH) {     // If button2 and buttonT are pressed   
     digitalWrite(led2, HIGH);      // Light led2
  }  
  
  if (buttonState3 == HIGH && buttonStateT == HIGH) {     // If button3 and buttonT are pressed   
     digitalWrite(led3, HIGH);      // Light led3
  }

  if (buttonState4 == HIGH && buttonStateF == HIGH) {     // If button4 and buttonF are pressed   
     digitalWrite(led4, HIGH);      // Light led4
  } 
 
  if (buttonState5 == HIGH && buttonStateF == HIGH) {     // If button5 and buttonF are pressed   
     digitalWrite(led5, HIGH);      // Light led5 
  }
  
  if (buttonState6 == HIGH && buttonStateF == HIGH) {     // If button6 and buttonF are pressed   
     digitalWrite(led6, HIGH);      // Light led6
  }
  

  
}

I will appreciate some some help or point me in the right direction,
Thanks in advance

You should think about your program as several pieces that are tied together in the loop()

One piece (which you already have) is PLAY

One piece is RESET

In your loop() you might get the user to press a button to start playing - the loop just runs round and round until that button is pressed. (But see below).

When the start button is pressed it calls a subroutine which is your play code.
When the game is finished you could have a short delay() so allow time for the lights to be seen, but better might be to require the user to press a button to return back to the loop()

You should probably have a variable that signifies that a game is finished and a reset is needed.

As well as checking if the start button is pressed the loop should be checking the variable to see if it needs to call the reset subroutine.

Some of this may be overkill for a very simple game but it is useful to think about programming problems in a modular way.

...R

Its not possible to add a START or RESET button... The game should always run ..waiting for an input and should reset with a timer of some kind

If I put a delay that will slow all the program right? not only when the game is done and all led are light.

You already have buttons - I didn't mean to add more, just use one of the ones you already have.

If the delay() is only called after all the questions are answered it won't affect anything else.

...R

Restarting is easy. Just keep track of which LEDs you have lit up. When all of them are lit, turn them all off.

The timeout is a bit trickier. You'll need to detect transitions, rather than states. A transition occurs when the state goes from HIGH to LOW, or LOW to HIGH. Detecting these transitions is done by keeping track of the last state. When the proper transition occurs, record the time. Outside of everything else, calculate the time since the last transition. If it is higher than a certain threshold, do the reset.

How to accomplish the bolded is demonstrated in the Blink Without Delay example. How to detect transitions is demonstrated within the State Change Detection example.

Normally, you would keep track input transitions, but in this instance, you may want to consider keeping track of output transitions.

I manage to close all led when the program detect all 6 led are on by using ledState variables and add a small delay to allow time to see all 6 led light up.

Now I only miss the inactivity timer and probably lot of optimization.

/*
 Test on MEGA 2560, must be use on UNO later
 */
 
 // Pin numbers
 const int buttonF = 30;      // button False , to replace by 14 (analog 0) with the Uno
 const int buttonT = 31;      // button True , to replace with 15(analog 1) with the Uno
 const int button1 = 2;      // button question 1
 const int button2 = 3;      // button question 2
 const int button3 = 4;      // button question 3
 const int button4 = 5;      // button question 4
 const int button5 = 6;      // button question 5
 const int button6 = 7;      // button question 6
 
 const int led1 = 13;
 const int led2 = 12;
 const int led3 = 11;
 const int led4 = 10;
 const int led5 = 9;
 const int led6 = 8;
 
 // states
 int buttonStateT = 0;
 int buttonStateF = 0;
 int buttonState1 = 0;
 int buttonState2 = 0;
 int buttonState3 = 0;
 int buttonState4 = 0;
 int buttonState5 = 0;
 int buttonState6 = 0;
 
 int ledState1 = 0;
 int ledState2 = 0;
 int ledState3 = 0;
 int ledState4 = 0;
 int ledState5 = 0;
 int ledState6 = 0;
 

 
 
 
 void setup(){
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(buttonF, INPUT);
  pinMode(buttonT, INPUT);
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
  pinMode(button5, INPUT);
  pinMode(button6, INPUT);

}
 
 void loop() {
   
  
  // check if the pushbutton is pressed.  
  buttonStateT = digitalRead(buttonT);  
  buttonStateF = digitalRead(buttonF); 
  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  buttonState3 = digitalRead(button3); 
  buttonState4 = digitalRead(button4);
  buttonState5 = digitalRead(button5);
  buttonState6 = digitalRead(button6);
  
 
  if (buttonState1 == HIGH && buttonStateT == HIGH) {     // If button1 and buttonT are pressed 
      ledState1 = 1;
     digitalWrite(led1, ledState1);      // Light led1
  }
  
  if (buttonState2 == HIGH && buttonStateT == HIGH) {     // If button2 and buttonT are pressed 
      ledState2 = 1;  
     digitalWrite(led2, ledState2);      // Light led2
  }  
  
  if (buttonState3 == HIGH && buttonStateT == HIGH) {     // If button3 and buttonT are pressed 
      ledState3 = 1;  
     digitalWrite(led3, ledState3);      // Light led3
  }

  if (buttonState4 == HIGH && buttonStateF == HIGH) {     // If button4 and buttonF are pressed   
      ledState4 = 1;
     digitalWrite(led4, ledState4);      // Light led4
  } 
 
  if (buttonState5 == HIGH && buttonStateF == HIGH) {     // If button5 and buttonF are pressed  
      ledState5 = 1; 
     digitalWrite(led5, ledState5);      // Light led5 
  }
  
  if (buttonState6 == HIGH && buttonStateF == HIGH) {     // If button6 and buttonF are pressed
      ledState6 = 1;  
     digitalWrite(led6, ledState6);      // Light led6
  }
   

     // Leds are turn off after 8 seconds when all leds light up
     if (ledState1 == 1 && ledState2 == 1 && ledState3 == 1 && ledState4 == 1 && ledState5 == 1 && ledState6 == 1){
       ledState1 = 0;
       ledState2 = 0;
       ledState3 = 0;
       ledState4 = 0;
       ledState5 = 0;
       ledState6 = 0;
       
       delay(8000);
     
     // set the LED with the ledState of the variable:
     digitalWrite(led1, ledState1);
     digitalWrite(led2, ledState2);
     digitalWrite(led3, ledState3);
     digitalWrite(led4, ledState4);
     digitalWrite(led5, ledState5);
     digitalWrite(led6, ledState6);
     }
  
  
}