user29698: 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() && randNumber == 0){
  Serial.println("You did it");
}
else {
  Serial.println("u failed");
}


user4143: 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.

29698: <p>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.</p>

<p>My code:</p>

<pre><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");
}
</code></pre>
 4143: <p>Don't use <code>delay()</code>, since nothing can happen (not even reading a button) while that delay is running.</p>

<p>Instead use <code>millis()</code> as in the <code>BlinkWithoutDelay</code> example sketch.</p>
