long randNumber; //settings
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C Lcd(0x27,16,2);
unsigned long myTime1;
unsigned long myTime2;
const int LED_PIN = 6;
const int TASTER_PIN = 3;
int PIEZO_PIN = 5;
void setup() {//setup
Lcd.backlight();
pinMode(LED_PIN, OUTPUT);
pinMode(TASTER_PIN, INPUT_PULLUP);
Serial.begin(9600);
Lcd.init();
Lcd.print("NWT Projekt Game");
delay(200);
}
void loop() { //loop
int zahl = random(0,2);
int tasterValue = digitalRead(TASTER_PIN);
while (tasterValue == 1) {
tasterValue = digitalRead(TASTER_PIN);
}
Lcd.clear();
Lcd.print("START"); //rolling display
for (int i = 0; i < 10; i++) {
Lcd.scrollDisplayRight();
delay(50);
}
Lcd.scrollDisplayRight();
Lcd.clear();
Lcd.setCursor(0,0);
delay(50);
Lcd.clear();
Lcd.setCursor(11,4);
Lcd.print("START");
for (int i = 0; i < 12; i++) {
Lcd.scrollDisplayLeft();
delay(50);
}
Lcd.setCursor(0,0);
Lcd.clear();
Lcd.print("Press Button");
delay(350);
Lcd.clear();
tasterValue = digitalRead(TASTER_PIN);
if (tasterValue == 0) { //if statement LED&PIEZO
if (zahl == 1) {
digitalWrite(LED_PIN, HIGH);
Serial.println("if clause 1 starting LED");
}
else {
tone(PIEZO_PIN,523);
}
myTime1 = millis();
while (tasterValue == 0) {
tasterValue = digitalRead(TASTER_PIN);
}
myTime2 = millis();
digitalWrite(LED_PIN, LOW);
Lcd.println("Reaktionszeit: ");
delay(1000);
Lcd.clear();
Lcd.println(myTime2-myTime1);
delay(1000);
Lcd.print("ms");
}
else {
Lcd.print("Nicht schummeln!");
delay(1000);
}
}