Reaction Game

I am trying to create a game where a series of 10 LEDs will turn on and off in order and when the button is pressed it will stop on the LED that is currently on.

I am having problems with stopping the LED when the sequence is active since it wont stop on the LED that is on at the time.

Any help is appreciated Many Thanks!

const int buttonPin = 2;
int buttonState = 0;

int LED_1 = 3;
int LED_2 = 4;
int LED_3 = 5;
int LED_4 = 6;
int LED_5 = 7;
int LED_6 = 8;
int LED_7 = 9;
int LED_8 = 10;
int LED_9 = 11;
int LED_10 = 12;

void setup() {
  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(LED_3, OUTPUT);
  pinMode(LED_4, OUTPUT);
  pinMode(LED_5, OUTPUT);
  pinMode(LED_6, OUTPUT);
  pinMode(LED_7, OUTPUT);
  pinMode(LED_8, OUTPUT);
  pinMode(LED_9, OUTPUT);
  pinMode(LED_10, OUTPUT);


  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  
  if (buttonState == HIGH) {
    
  digitalWrite(3, HIGH);
  delay (100);
  digitalWrite(3, LOW);
  
  digitalWrite(4, HIGH);
  delay (90);
  digitalWrite(4, LOW);
  
  digitalWrite(5, HIGH);
  delay (80);
  digitalWrite(5, LOW);
  
  digitalWrite(6, HIGH);
  delay (70);
  digitalWrite(6, LOW);
  
  digitalWrite(7, HIGH);
  delay (50);
  digitalWrite(7, LOW);
  
  digitalWrite(8, HIGH);
  delay (50);
  digitalWrite(8, LOW);
  
  digitalWrite(9, HIGH);
  delay (70);
  digitalWrite(9, LOW);
  
  digitalWrite(10, HIGH);
  delay (80);
  digitalWrite(10, LOW);

  digitalWrite(11, HIGH);
  delay (90);
  digitalWrite(11, LOW);

  digitalWrite(12, HIGH);
  delay (100);
  digitalWrite(12, LOW);

  digitalWrite(11, HIGH);
  delay (90);
  digitalWrite(11, LOW);

  digitalWrite(10, HIGH);
  delay (80);
  digitalWrite(10, LOW);

  digitalWrite(9, HIGH);
  delay (70);
  digitalWrite(9, LOW);

  digitalWrite(8, HIGH);
  delay (50);
  digitalWrite(8, LOW);

  digitalWrite(7, HIGH);
  delay (50);
  digitalWrite(7, LOW);

  digitalWrite(6, HIGH);
  delay (70);
  digitalWrite(6, LOW);

  digitalWrite(5, HIGH);
  delay (80);
  digitalWrite(5, LOW);

  digitalWrite(4, HIGH);
  delay (90);
  digitalWrite(4, LOW);
  
  } else {
    digitalWrite(, HIGH);
  }
}

First you need to eliminate the delay()s Have a look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

You also need to fix the error in the code so that it compiles     digitalWrite(, HIGH);Which pin are you trying to turn HIGH ?

Many thanks I will have a look at those threads!

As for which LED I am trying to turn on: I would like the LED that is currently in use to stay on.

e.g. LEDs 1-10 lighting on and turning off in order but when the button is pressed the LED that is currently on should stay on.

So if LED 5 is (HIGH) when the button is pressed then it should stay high but if LED 4 is (HIGH) when the button is pressed than it should stay high.

However I want this to be the case for all the LEDs so no matter which one is (HIGH) at the time it will stay high when the button is pressed.

Sorry for the long reply not quite sure how to explain it properly...

int LED_1 = 3;
int LED_2 = 4;
int LED_3 = 5;
int LED_4 = 6;
int LED_5 = 7;
int LED_6 = 8;
int LED_7 = 9;
int LED_8 = 10;
int LED_9 = 11;
int LED_10 = 12;

Your code would be orders of magnitude simpler if you had an array of pin numbers.

  pinMode(buttonPin, INPUT);

How IS your switch wired? Why aren't you using the much simpler wiring possible by using INPUT_PULLUP as the mode?

You need to make lighting a particular LED, and reading the state of the switch, completely independent activities.