Advertisement
Guest User

Arduino Reflex Tester

a guest
Jan 16th, 2018
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. #include <Wire.h>  
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. #define ledPin 8
  5. #define btnPin 4
  6.  
  7. double number;
  8. long sTime;
  9.  
  10. LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  11.  
  12. void setup() {
  13.   Serial.begin(9600);
  14.   lcd.begin(16,2);  
  15.   lcd.setCursor(0,0);
  16.   pinMode(btnPin, INPUT);
  17.   pinMode(ledPin, OUTPUT);
  18. }
  19.  
  20. void loop() {
  21.     number = random(500, 5000);
  22.     lcd.print("Wait for the LED");
  23.     delay(number);
  24.  
  25.     lcd.clear();
  26.     lcd.print("     PRESS!");
  27.     digitalWrite(ledPin, HIGH);
  28.     sTime = millis();
  29.  
  30.     while (digitalRead(btnPin) == LOW);
  31.  
  32.     lcd.clear();
  33.     lcd.print(" Reaction time: ");
  34.     lcd.setCursor(0,1);
  35.     lcd.print("      ");
  36.     lcd.print((millis() - sTime) / 1000.0);
  37.     lcd.print(" s");
  38.    
  39.     delay(2000);
  40.  
  41.     lcd.clear();
  42.     lcd.setCursor(0,0);
  43.     lcd.print("  Another test");
  44.     lcd.setCursor(0, 1);
  45.     lcd.print("  in 5 seconds");
  46.     delay(5000);
  47.     lcd.clear();
  48.     digitalWrite(8, LOW);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement