I am making an easy game but something in my code is wrong I am making a game where you need to push the button when the LED lights up but it is not registering the push at the right time. I need to push the button when LED is about to go off.

My code:

randNumber = random(2);

if(randNumber == 0){
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
}

if (btnAddFirst.pressed() &amp;&amp; randNumber == 0){
  Serial.println("You did it");
}
else {
  Serial.println("u failed");
}
Don't use delay(), since nothing can happen (not even reading a button) while that delay is running.

Instead use millis() as in the BlinkWithoutDelay example sketch.