# Pin 3 -> LED # Pin 8 -> React button, pressed 8 HIGH, not preesed LOW # Pin 9 -> Start button, pressed 8 HIGH, not preesed LOW const int reset = 9; const int react = 8; const int led = 3; unsigned long starttime; unsigned long endtime; float result; void setup() { // put your setup code here, to run once: pinMode(reset, INPUT); pinMode(react, INPUT); pinMode(led, OUTPUT); digitalWrite(led,LOW); randomSeed(analogRead(A0)); Serial.begin(9600); } void play(){ int randomtime = random(1,6); delay(randomtime*1000); digitalWrite(led, HIGH); Serial.println("LED is ON"); starttime = millis(); if(digitalRead(react)){ Serial.println("STOP CHEATING!!!"); return; } while(!digitalRead(react)){ } endtime = millis(); Serial.print("Reflex time is : " ); result = endtime-starttime; Serial.println(result ); Serial.print(result/1000); Serial.println(" s" ); return; } void loop() { // put your main code here, to run repeatedly: if(digitalRead(reset)){ digitalWrite(led, LOW); Serial.println("LED is OFF"); play(); } }