This lesson will use a LCD this is the reason why you are invited to read the lesson Arduino & LCDs before you start.
2. SchematicThe schematic is very simple. There are all the connections needed to use the LCD and three buttons that from left to right are UP, DOWN and START/STOP.
When the Arduino is powered on you'll be invited to set a countdown. Use the UP and DOWN button to choose the count and the START/STOP button to choose it. After a countdown will start and when the GO signal will appear on the screen you have to press the START/STOP button as soon as possible.
In base of your score a different message will appear on the screen:
- Well done! if
0 < elapsed <= 350
;
- Not bad! if
350 < elapsed <= 500
;
- Try again please otherwise;
Here is the code:
/*
Test your ability with the Reaction Timer
author: Arturo Guadalupi
*/
// include the library code:
#include
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int count = 0;
void setup() {
lcd.begin(16, 2);
pinMode(10, OUTPUT);
pinMode(A0, INPUT); //UP button
pinMode(A1, INPUT); //DOWN button
pinMode(A2, INPUT); //START/STOP button
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Arduino");
lcd.setCursor(0, 1);
lcd.print("Reaction Timer!");
delay(2000);
lcd.clear();
delay(1000);
}
void loop() {
SetCountdown(); //function to set the countdown
countdown(); //function for the countdown
reaction(); //function who count your reaction
}
void SetCountdown()
{
lcd.clear();
lcd.print("Please set the");
lcd.setCursor(0, 1);
lcd.print("countdown");
delay(2000);
lcd.clear();
while (digitalRead(A2) != LOW) //while you not press START
{
if (digitalRead(A0) == LOW) //if UP is pressed
{
count++;
delay(200);
lcd.clear();
}
if (count > 10) //10 seconds are enough to prepare yourself!
count = 0;
if (digitalRead(A1) == LOW) //if DOWN is pressed
{
count--;
delay(200);
lcd.clear();
}
if (count 350 && elapsed 500)
lcd.print("Try again please");
delay(1500);
}
Comments
Please log in or sign up to comment.