// Copyright Santhosh Venugopal™℗®© & Justus Wolff™℗®© #include #include // Bonus code class pixeldraw { private: LiquidCrystal_I2C* lcd; void constructbuf(int x, int y, byte* buf) { buf[y] = B10000 >> x; return buf; } public: pixeldraw(LiquidCrystal_I2C* _lcd) { lcd = _lcd; } void setpix(int _x, int _y) { // calculate cell x and y int cellx = _x/5; int celly = _y/8; int x = _x%5; // calculate modulo int y = _y%8; // calculate modulo byte buf[8] = { // load from cellbuf 0,0,0,0,0,0,0,0 }; constructbuf(x,y,buf); lcd->createChar(cellx+(celly*16), buf); lcd->clear(); lcd->setCursor(cellx, celly); lcd->write(byte(cellx+(celly*16))); } }; int led = 7; // pin Nummern für jwl. Komponente int bt = 8; long highscore = 999999; // speichert highscore in einer Variable LiquidCrystal_I2C lcd(0x27,16,2); // LCD deklarieren void setup() { // put your setup code here, to run once: pinMode(led, OUTPUT); pinMode(bt, INPUT_PULLUP); // pinmodes setzen (selbsterklärend) randomSeed(analogRead(A1)); // Zufallsgenerator initialisieren Serial.begin(9600); Serial.println("Santhosh Justus Reaktionstester debug Information"); lcd.init(); // LCD initialisieren lcd.clear(); lcd.backlight(); // backlight an machen pixeldraw drawer(&lcd); for (int y=0;y<(8*8);y++) { for (int x=0;x<(16*5);x++) { drawer.setpix(x, y); delay(1); } } } void loop() { lcd.setCursor(0, 0); lcd.print("klicke sobald"); lcd.setCursor(0, 1); lcd.print("Die LED leuchtet"); // gebrauchsanleitung für tester int del = random(300, 3000); // Wartezeit für das Leuchten der LED Serial.println("--------------------------------------"); // extra Informationen im seriellen Monitor Serial.print("Wartezeit:"); // debug Serial.println(del); // debug delay(del); // warten while (digitalRead(bt)==0) { // warten bis nicht mehr gedrückt Serial.println("Versuch zu schummeln."); // debug delay(random(300, 3000)); // zufällige Zeit warten bis zur nächsten Überprüfung } long t1 = millis(); digitalWrite(led, HIGH); while (digitalRead(bt)==1) {} // warten bis gedrückt t1 = millis()-t1; // berechnen der reaktionszeit digitalWrite(led, LOW); Serial.print("Ergebnis: "); // debug Serial.println(t1); // debug lcd.clear(); // anzeigen der reaktionszeit lcd.setCursor(0, 1); lcd.print(t1); lcd.print("ms"); lcd.setCursor(0, 0); lcd.print("Reaktionszeit:"); delay(100); while (digitalRead(bt)==0) {} // warten bis nicht gedrückt while (digitalRead(bt)==1) {} // warten bis gedrückt delay(100); if (t1 < highscore) { // highscore logik, zeigt "highscore" falls Reaktionszeit am niedrigsten ist bzw. < highscore highscore = t1; Serial.println("Highscore"); lcd.clear(); lcd.setCursor(0,0); lcd.print("--HIGHSCORE!!!--"); lcd.setCursor(0,1); lcd.print("Zeit:"); lcd.print(t1); Serial.println("wartet bis drücken"); while (digitalRead(bt)==1) {} // warten bis gedrückt } lcd.clear(); // cleanup delay(1000); }