Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #define ledPin 8
- #define btnPin 4
- double number;
- long sTime;
- LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- void setup() {
- Serial.begin(9600);
- lcd.begin(16,2);
- lcd.setCursor(0,0);
- pinMode(btnPin, INPUT);
- pinMode(ledPin, OUTPUT);
- }
- void loop() {
- number = random(500, 5000);
- lcd.print("Wait for the LED");
- delay(number);
- lcd.clear();
- lcd.print(" PRESS!");
- digitalWrite(ledPin, HIGH);
- sTime = millis();
- while (digitalRead(btnPin) == LOW);
- lcd.clear();
- lcd.print(" Reaction time: ");
- lcd.setCursor(0,1);
- lcd.print(" ");
- lcd.print((millis() - sTime) / 1000.0);
- lcd.print(" s");
- delay(2000);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print(" Another test");
- lcd.setCursor(0, 1);
- lcd.print(" in 5 seconds");
- delay(5000);
- lcd.clear();
- digitalWrite(8, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement