Victor Onofrei
Published © GPL3+

Arduino "Reaction Timer" - My Kids Love Playing This

Wait for light - press a button. So simple but so funny. All our family plays the game.

BeginnerProtip3,934
Arduino "Reaction Timer" - My Kids Love Playing This

Things used in this project

Hardware components

LED (generic)
LED (generic)
×2
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
Slide Switch
Slide Switch
×1
Resistor 10k ohm
Resistor 10k ohm
×2
Battery Holder, 3 x AAA
Battery Holder, 3 x AAA
×1
Arduino Micro
Arduino Micro
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

My first fritzing essay

Code

Here's the code

Arduino
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#define btnSTART 5
#define btnHIT 7
#define ledTrigger 9
LiquidCrystal_I2C lcd(0x23,20,4);

void setup() {
  lcd.init(); 
  lcd.backlight();
  pinMode(btnSTART, INPUT_PULLUP);
  pinMode(btnHIT, INPUT_PULLUP);
  pinMode(ledTrigger, OUTPUT);
  digitalWrite(ledTrigger, LOW);
  lcd.print("Salut Famille!");
  delay(2000);
  lcd.clear();
  randomSeed(analogRead(0));
}

void loop() {
  long timeReaction;
  long timeTotal = 0;
  lcd.print("Press START!");
  while (digitalRead(btnSTART)) {}
  delay(10);
  while (!digitalRead(btnSTART)) {}
  lcd.clear();
  lcd.print("Jouez!!!");
  delay(1000);
  for (int i = 0; i < 5; i++) {
    delay(random(500, 5000));
    timeReaction = millis();
    digitalWrite(ledTrigger, HIGH);
    while (digitalRead(btnHIT)) {}
    timeReaction = millis() - timeReaction;
    timeTotal += timeReaction;
    delay(10);
    while (!digitalRead(btnHIT)) {}
    digitalWrite(ledTrigger, LOW);
    lcd.clear();
    lcd.print(i + 1);
    lcd.print(": ");
    lcd.print(timeReaction);
    delay(1000);
  }
  lcd.clear();
  lcd.print("Moyenne = ");
  lcd.print(timeTotal/5);
  delay(10000);
  lcd.clear();
  }

Credits

Victor Onofrei

Victor Onofrei

1 project • 64 followers

Comments