Guest User

Arduino Reflex Tester

a guest
Jan 16th, 2018
514
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×