/* Arduino Two Player Reaction Timer Game Made By- Saiyam Agrawal Sorry for not adding the // comments */ #include LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int buzzer = 6; int led1 = 7; int led2 = 8; int led3 = 9; int time1 = 0; int time2 = 0; void onlyblink() { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); delay(500); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); delay(500); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); delay(500); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); delay(500); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); } void blinkbeep() { digitalWrite(buzzer, HIGH); delay(100); digitalWrite(buzzer, LOW); delay(100); digitalWrite(buzzer, HIGH); delay(100); digitalWrite(buzzer, LOW); delay(100); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); delay(500); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); delay(500); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); delay(500); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); delay(500); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); delay(2000); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); } void setup() { lcd.begin(16,2); delay(1000); lcd.clear(); pinMode(buzzer, OUTPUT); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(10, INPUT); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); lcd.print("***Welcome***"); blinkbeep(); delay(3000); lcd.clear(); lcd.print(" Reaction Timer "); lcd.setCursor(0,1); lcd.print(" Game "); delay(3000); } void loop() { lcd.clear(); lcd.print("Press Button"); lcd.setCursor(0,1); lcd.print("On Fourth Beep"); delay(5000); lcd.clear(); lcd.print("Player1's Turn"); delay(5000); lcd.clear(); lcd.print("Get Ready!!"); delay(5000); digitalWrite(buzzer, HIGH); lcd.clear(); lcd.print("3......"); delay(100); digitalWrite(buzzer, LOW); delay(900); digitalWrite(buzzer, HIGH); digitalWrite(led1, HIGH); lcd.clear(); lcd.print("2......"); delay(100); digitalWrite(buzzer, LOW); delay(900); digitalWrite(buzzer, HIGH); digitalWrite(led2, HIGH); lcd.clear(); lcd.print("1......"); delay(100); digitalWrite(buzzer, LOW); delay(random(3000,8000)); digitalWrite(buzzer, HIGH); digitalWrite(led3, HIGH); lcd.clear(); lcd.print("GO!!!!!!!"); int d = 0; while(d < 2000 && digitalRead(10)!=HIGH) { delay(1); d++; } digitalWrite(buzzer, LOW); time1 = d; lcd.clear(); lcd.print("Your Reaction"); lcd.setCursor(0,1); lcd.print("Time= "); lcd.print(time1); lcd.print(" ms."); onlyblink(); delay(4000); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); lcd.clear(); lcd.print("Player2's Turn"); delay(5000); lcd.clear(); lcd.print("Get Ready!!"); delay(5000); digitalWrite(buzzer, HIGH); lcd.clear(); lcd.print("3......"); delay(100); digitalWrite(buzzer, LOW); delay(900); digitalWrite(buzzer, HIGH); digitalWrite(led1, HIGH); lcd.clear(); lcd.print("2......"); delay(100); digitalWrite(buzzer, LOW); delay(900); digitalWrite(buzzer, HIGH); digitalWrite(led2, HIGH); lcd.clear(); lcd.print("1......"); delay(100); digitalWrite(buzzer, LOW); delay(random(3000,8000)); digitalWrite(buzzer, HIGH); digitalWrite(led3, HIGH); lcd.clear(); lcd.print("GO!!!!!!!"); int e = 0; while(e<2000 && digitalRead(10)!=HIGH) { delay(1); e++; } digitalWrite(buzzer, LOW); time2 = e; lcd.clear(); lcd.print("Your Reaction"); lcd.setCursor(0,1); lcd.print("Time= "); lcd.print(time2); lcd.print(" ms."); onlyblink(); delay(4000); if(time2>time1) { lcd.clear(); lcd.print("Player1 Wins!:D"); blinkbeep(); delay(3000); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); lcd.clear(); lcd.print("Thank You"); lcd.setCursor(0,1); lcd.print("For Playing :D"); delay(10000); } else if(time2