Dateien nach "/" hochladen

This commit is contained in:
2026-03-03 08:57:38 +01:00
parent 70d54afe48
commit 4c066985c1
3 changed files with 158 additions and 105 deletions

View File

@@ -3,40 +3,10 @@
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
// 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
uint8_t led = 7; // pin Nummern für jwl. Komponente
uint8_t bt = 8;
uint32_t highscore = -1; // wer hier einen bitoverflow hinbekommt verdient den respekt
uint8_t godmode = 0;
LiquidCrystal_I2C lcd(0x27,16,2); // LCD deklarieren
void setup() {
@@ -50,37 +20,54 @@ void setup() {
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 handlecmds() {
if (!Serial.available()) {return;}
String cmd = Serial.readString();
if (cmd == "godmode enable\n") {
godmode = 1;
Serial.println("Okidoki, du citri!");
}
if (cmd == "godmode disable\n") {
godmode = 0;
Serial.println("Whad de fug, bong ding ow");
}
if (cmd == "ich bin ein cheater\n") {
godmode = 2;
Serial.println(">:(");
}
if (cmd == "ich bin KEIN cheater\n") {
godmode = 0;
Serial.println("aight bet");
}
}
void loop() {
handlecmds();
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
uint16_t 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
while (digitalRead(bt)==0 || godmode == 2) { // warten bis nicht mehr gedrückt
handlecmds();
Serial.println("Versuch zu schummeln."); // debug
delay(random(300, 3000)); // zufällige Zeit warten bis zur nächsten Überprüfung
}
long t1 = millis();
uint32_t t1 = millis();
digitalWrite(led, HIGH);
while (digitalRead(bt)==1) {} // warten bis gedrückt
while (digitalRead(bt)==1 && godmode == 0) {} // warten bis gedrückt
t1 = millis()-t1; // berechnen der reaktionszeit