user54973: I've written this code for a reaction timer game. The reaction time is to be displayed in milliseconds to the serial monitor as accurately as possible. The reaction time is not being displayed correctly. I'm including my timer setup routine and where I increment milliseconds. 
TCCR1A=0; 
TCCR1B=0; 
timer1_counter=65536; 
TCNT1=timer1_counter; 
TCCR1B |=(1<<CS12); 

TIMSK1 |=(1<<TOIE1); 
interrupts();  
}

ISR(TIMER1_OVF_vect) 
{
  TCNT1=timer1_counter; 
  int_flag=1;
 }



  digitalWrite(LED,LOW); 
  randomSeed(analogRead(A1)); 
  NumSecs=random(1000,7000);  
  delay(NumSecs);  
  digitalWrite(LED,HIGH);
  while(digitalRead(PUSHBUTTON) == HIGH)  
  {
  }
  if (int_flag==1){
  millisecs++;
  int_flag=0;
  }


user2967: You're over-thinking this:
  digitalWrite(LED,LOW); 
  randomSeed(analogRead(A1)); 
  NumSecs=random(1000,7000);  
  delay(NumSecs);  
  digitalWrite(LED,HIGH);
  unsigned int startTime = millis();
  while(digitalRead(PUSHBUTTON) == HIGH)  
  {
  }
  unsigned int elapsed = millis() - startTime;

After that code, elapsed will contain the number of milliseconds it took the user to press the button. Note, however, that the user could cheat and simply press the button the whole time while waiting for the LED to change states. You could add logic to make sure the button isn't pressed just before you change the LED state, but I'll leave that up to you.

54973: <p>I've written this code for a reaction timer game. The reaction time is to be displayed in milliseconds to the serial monitor as accurately as possible. The reaction time is not being displayed correctly. I'm including my timer setup routine and where I increment milliseconds. </p>

<pre><code>TCCR1A=0; 
TCCR1B=0; 
timer1_counter=65536; 
TCNT1=timer1_counter; 
TCCR1B |=(1&lt;&lt;CS12); 

TIMSK1 |=(1&lt;&lt;TOIE1); 
interrupts();  
}

ISR(TIMER1_OVF_vect) 
{
  TCNT1=timer1_counter; 
  int_flag=1;
 }



  digitalWrite(LED,LOW); 
  randomSeed(analogRead(A1)); 
  NumSecs=random(1000,7000);  
  delay(NumSecs);  
  digitalWrite(LED,HIGH);
  while(digitalRead(PUSHBUTTON) == HIGH)  
  {
  }
  if (int_flag==1){
  millisecs++;
  int_flag=0;
  }
</code></pre>
 2967: <p>You're over-thinking this:</p>

<pre><code>  digitalWrite(LED,LOW); 
  randomSeed(analogRead(A1)); 
  NumSecs=random(1000,7000);  
  delay(NumSecs);  
  digitalWrite(LED,HIGH);
  unsigned int startTime = millis();
  while(digitalRead(PUSHBUTTON) == HIGH)  
  {
  }
  unsigned int elapsed = millis() - startTime;
</code></pre>

<p>After that code, <code>elapsed</code> will contain the number of milliseconds it took the user to press the button. Note, however, that the user could cheat and simply press the button the whole time while waiting for the LED to change states. You could add logic to make sure the button isn't pressed just before you change the LED state, but I'll leave that up to you.</p>
