# 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 react1 = 7; const int react2 = 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(react1, INPUT); pinMode(react2, 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(react1) || digitalRead(react2)){ Serial.println("STOP CHEATING!!!"); return; } while(true){ if(digitalRead(react1)){ Serial.println("Player 1 wins!!!"); break; } if(digitalRead(react2)){ Serial.println("Player 2 wins!!!"); break; } } 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(); } }