From 9fe747507589dd82cc443e57ce1eeae89c628a37 Mon Sep 17 00:00:00 2001 From: danielvici123 <94993276+danielvici@users.noreply.github.com> Date: Wed, 26 Feb 2025 12:29:59 +0100 Subject: [PATCH] inf unf prog aufgabe/mitschrieb --- INF/i2c/i2c.ino | 10 +-- INF/i2c_lm75/i2c_lm75.ino | 28 ++++++++ INF/led-display/led-display.ino | 83 +++++++++++++++++++++++ progp/25-2-26 - class/lehrer-class.php | 40 +++++++++++ progp/25-2-26 - class/lehrer-test.php | 61 +++++++++++++++++ progp/25-2-26 - class/personen-class.php | 42 ++++++++++++ progp/25-2-26 - class/schueler-class.php | 59 ++++++++++++++++ 7 files changed, 319 insertions(+), 4 deletions(-) create mode 100644 INF/i2c_lm75/i2c_lm75.ino create mode 100644 INF/led-display/led-display.ino create mode 100644 progp/25-2-26 - class/lehrer-class.php create mode 100644 progp/25-2-26 - class/lehrer-test.php create mode 100644 progp/25-2-26 - class/personen-class.php create mode 100644 progp/25-2-26 - class/schueler-class.php diff --git a/INF/i2c/i2c.ino b/INF/i2c/i2c.ino index fc5fa2c..798a844 100644 --- a/INF/i2c/i2c.ino +++ b/INF/i2c/i2c.ino @@ -9,18 +9,20 @@ void setup() { void loop() { // Daten senden // 0b um in 0 und 1 zu schreiben ansonsten Hex - // 0111 <- absch. 0000 <- Jumper ablesen - Wire.beginTransmission(0b0111000); + // 0111 <- absch. 0000 <- Jumper + Serial.begin(115200); + Wire.beginTransmission(0b0111101); //Wire.write(0b00001111); // da LED LOW Active 0->AN, 1->AUS; mann muss 8 Bits machen //Wire.endTransmission(); delay(500); // Daten empfangen byte Daten1; // 1 Byte deklarieren - Wire.requestFrom(0b0100110, 1); + Wire.requestFrom(0b1001010, 1); if (Wire.available() >= 1){ Daten1 = Wire.read(); // Daten lesen - Wire.write(Daten1); + //Wire.write(Daten1); + Serial.println(Daten1); } Wire.endTransmission(); } diff --git a/INF/i2c_lm75/i2c_lm75.ino b/INF/i2c_lm75/i2c_lm75.ino new file mode 100644 index 0000000..3dac854 --- /dev/null +++ b/INF/i2c_lm75/i2c_lm75.ino @@ -0,0 +1,28 @@ +#include "Wire.h" +// absch -> Abschreiben + +void setup() { + Wire.begin(); + Serial.begin(115200); +} + +void loop() { + // Daten senden + // 0b um in 0 und 1 zu schreiben ansonsten Hex + // 0111 <- absch. 0000 <- Jumper + + Wire.beginTransmission(0b0111101); + //Wire.write(0b00001111); // da LED LOW Active 0->AN, 1->AUS; mann muss 8 Bits machen + //Wire.endTransmission(); + delay(500); + + // Daten empfangen + byte Daten1; // 1 Byte deklarieren + Wire.requestFrom(0b1001010, 1); + if (Wire.available() >= 1){ + Daten1 = Wire.read(); // Daten lesen + //Wire.write(Daten1); + Serial.println(Daten1); + } + Wire.endTransmission(); +} \ No newline at end of file diff --git a/INF/led-display/led-display.ino b/INF/led-display/led-display.ino new file mode 100644 index 0000000..4061dae --- /dev/null +++ b/INF/led-display/led-display.ino @@ -0,0 +1,83 @@ +/* INFP-Übungen zum I2C-Bus - https://kurzelinks.de/wvs_esp_12 + * Benötigte Bibliotheken + * Wire.h (integriert) + * die 2 Bibliotheken müssen in Arduino noch hinzugefügt werden: + * https://github.com/ThingPulse/esp8266-oled-ssd1306 + * https://github.com/johnrickman/LiquidCrystal_I2C + * Fügt zur Schaltung das Bauteil "LCD 16x2 (I2C)" hinzu und ergänzt + * die Verdrahtung. Danach die Serial.print-Ausgaben ersetzten durch + * Ausgaben auf dem Text-Display + * Gute Zusammenfassung zum Display + * https://docs.wokwi.com/parts/wokwi-lcd1602 + * https://sprut.de/electronic/lcd/index.htm + */ +#include +#include "SSD1306Wire.h" +#include // Die Bibliothek muss noch installiert werden! + +//***** Portpins für Ein-/Ausgänge *************************************** +const int Enc_A = 34, Enc_B = 35, Enc_Taster = 0, NEO_Pin=26; +const int LED_rot = 32, LED_gruen = 33, Taster2 = 2, Taster4 = 4; + +//***** Objekt für Displays anlegen +SSD1306Wire display(0x3c, SDA, SCL); +LiquidCrystal_I2C lcd(0x27, 16, 2); // Display mit 2 Zeilen, 16 Zeichen, I2C-Adresse 0x27 (PCF8574!) + +// ***** Globale Variablen ************************************************ +bool T2_neu, T2_alt, T4_neu, T4_alt; // für Flankenerkennung +unsigned long currentMillis, nextMillis; +int Digitalwert; + +// ***** Initialisierung ************************************************** +void setup() { + Serial.begin(115200); // Serielle Schnittstelle mit 115200Bit/s + pinMode(LED_rot, OUTPUT); // die LEDs beginnen danach + pinMode(LED_gruen, OUTPUT); // zu leuchten! + digitalWrite(LED_rot, HIGH); // also beide ausschalten + digitalWrite(LED_gruen, HIGH); + pinMode(Taster2, INPUT_PULLUP); // Taster brauchen hier den + pinMode(Taster4, INPUT_PULLUP); // Pullup-Widerstand + + // SSD1306 Display initialisieren + display.init(); + display.flipScreenVertically(); + display.setContrast(255); + display.setFont(ArialMT_Plain_16); + + // I2C Textdisplay 1602 initialisieren, Text ausgeben + // siehe Arduino-Beispiel "Hello World" + lcd.init(); + // Print a message to the LCD. + lcd.backlight(); + lcd.setCursor(0,0); + lcd.print("danielvici.com"); +} + +// ***** Endlosschleife *************************************************** +void loop() { + currentMillis = millis( ); + if ( currentMillis >= nextMillis ) { + nextMillis = currentMillis + 1000; // 1x pro Sekunde Messen + Digitalwert = analogRead(A0); // Poti einlesen + Serial.printf("Digitalwert: %d\n", Digitalwert); + display.clear(); + display.drawString(16, 8, "Digitalwert"); + char buf[5]; + sprintf(buf, "%4d", Digitalwert); + display.drawString(16, 32, buf); + display.display( ); + } + + + // Flankenerkennung, Anmerkung: die Taster in Wokwi können mit prellen + // konfiguriert werden, so dass die LED manchmal mehrfach umschaltet + // -> also auch hier kann entprellen getestet werden. + T2_neu = digitalRead(Taster2); + if ( T2_neu == 0 && T2_alt == 1) { // fallende Flanke = Tastendruck + digitalWrite(LED_rot, !digitalRead(LED_rot)); // toggeln + } + T2_alt = T2_neu; // für Flankenerkennung +} + +// ***** Eigene Funktionen ************************************************ + diff --git a/progp/25-2-26 - class/lehrer-class.php b/progp/25-2-26 - class/lehrer-class.php new file mode 100644 index 0000000..80dca5b --- /dev/null +++ b/progp/25-2-26 - class/lehrer-class.php @@ -0,0 +1,40 @@ +setGehaltsstufe($gs); + } + + // Öffentliche Zugriffsfunktionen + // Setter + public function setGehaltsstufe(int $gs): void { + $this->gehaltsstufe = $gs; + } + + // Getter + public function getGehaltsstufe(): int { + return $this->gehaltsstufe; + } + + // Sonstige Funktionen + public function ausgabe() { + echo "

"; + echo "Vorname: $this->vorname
"; + echo "Nachname: $this->nachname
"; + echo "Gehaltsstufe: A$this->gehaltsstufe"; + echo "

"; + } + + public function befoerdern():bool{ + if($this->gehaltsstufe < 16){ + $this->gehaltsstufe++; + return true; + } + return false; + } +} +?> \ No newline at end of file diff --git a/progp/25-2-26 - class/lehrer-test.php b/progp/25-2-26 - class/lehrer-test.php new file mode 100644 index 0000000..f55df27 --- /dev/null +++ b/progp/25-2-26 - class/lehrer-test.php @@ -0,0 +1,61 @@ + + + + + + Document + + +Lehrer"; +$l = new Lehrer("Michael", "Staudt", 13); +$l->ausgabe(); +if($l->befoerdern()){ + echo "

Beförderung erfolgreich!

"; + echo "Neue Stufe: ".$l->getGehaltsstufe()."

"; +}else { + echo "

Beförderung nicht erfolgreich, da höchste Stufe erreicht

"; +} + +// $l->ausgabe(); +$l->befoerdern(); // A15 +$l->befoerdern(); // A16 +$l->befoerdern(); // A17 +$l->befoerdern(); // A18 + +// A18 -> A19 +if($l->befoerdern()){ + echo "

Beförderung erfolgreich!

"; + echo "Neue Stufe: ".$l->getGehaltsstufe()."

"; +}else { + echo "

Beförderung nicht erfolgreich, da höchste Stufe erreicht

"; +} + +// ------------------------ +// S C H U E L E R T E S T +// ------------------------ + +echo "

Schüler

"; +$s = new Schueler("daniel", "vici123", "2BKI1"); +$s->ausgabe(); + +// -------------------- +// P E R S O N T E S T +// -------------------- + +echo "

Personen

"; +$p = new Person("danielvici", "123"); +$p->ausgabe(); + +?> + + \ No newline at end of file diff --git a/progp/25-2-26 - class/personen-class.php b/progp/25-2-26 - class/personen-class.php new file mode 100644 index 0000000..959c680 --- /dev/null +++ b/progp/25-2-26 - class/personen-class.php @@ -0,0 +1,42 @@ +setVorname($vn); + $this->setNachname($nn); + } + + // Öffentliche Zugriffsfunktionen + // Setter + public function setVorname(string $vn): void { + $this->vorname = $vn; + } + + public function setNachname(string $nn): void { + $this->nachname = $nn; + } + + // Getter + public function getVorname(): string { + return $this->vorname; + } + + public function getNachname(): string { + return $this->nachname; + } + + // Sonstige Funktionen + public function ausgabe() { + echo "

"; + echo "Vorname: $this->vorname
"; + echo "Nachname: $this->nachname
"; + echo "

"; + } + +} +?> \ No newline at end of file diff --git a/progp/25-2-26 - class/schueler-class.php b/progp/25-2-26 - class/schueler-class.php new file mode 100644 index 0000000..d53062d --- /dev/null +++ b/progp/25-2-26 - class/schueler-class.php @@ -0,0 +1,59 @@ +setVorname($vn); + $this->setNachname($nn); + $this->setKlasse($kl); + } + + // Öffentliche Zugriffsfunktionen + // Setter + public function setVorname(string $vn): void { + $this->vorname = $vn; + } + + public function setNachname(string $nn): void { + $this->nachname = $nn; + } + + public function setKlasse(string $kl): void { + $this->klasse = $kl; + } + + // Getter + public function getVorname(): string { + return $this->vorname; + } + + public function getNachname(): string { + return $this->nachname; + } + + public function getKlasse(): string { + return $this->klasse; + } + + // Sonstige Funktionen + public function ausgabe() { + echo "

"; + echo "Vorname: $this->vorname
"; + echo "Nachname: $this->nachname
"; + echo "Klasse: $this->klasse"; + echo "

"; + } + + public function versetzen():bool{ + if($this->klasse == "2BKI1"){ + $this->klasse = "2BKI2"; + return true; + } + return false; + } +} +?> \ No newline at end of file