ESP Programme
This commit is contained in:
parent
6c94f6595c
commit
91072f3405
2 changed files with 125 additions and 0 deletions
81
ESP in WLAN zeigt IP.txt
Normal file
81
ESP in WLAN zeigt IP.txt
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
#include <WiFi.h> // WLAN-Funktion für ESP32
|
||||||
|
#include <Wire.h> // I2C Kommunikation (für OLED)
|
||||||
|
#include <Adafruit_GFX.h> // Grafik-Basisbibliothek (Text, Linien)
|
||||||
|
#include <Adafruit_SSD1306.h> // OLED-Treiber (SSD1306 Display)
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH 128 // OLED Breite in Pixeln
|
||||||
|
#define SCREEN_HEIGHT 64 // OLED Höhe in Pixeln
|
||||||
|
|
||||||
|
// OLED Display Objekt erstellen
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
|
||||||
|
|
||||||
|
// WLAN Zugangsdaten
|
||||||
|
const char* ssid = "Galaxy Julian";
|
||||||
|
const char* password = "0987654321";
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// Funktion: zeigt IP-Adresse und WLAN Status an
|
||||||
|
// -----------------------------------------------------
|
||||||
|
void showIP(String ip)
|
||||||
|
{
|
||||||
|
display.clearDisplay(); // Bildschirm löschen (neuer Frame)
|
||||||
|
|
||||||
|
display.setTextSize(2); // große Schrift (Achtung: braucht viel Platz)
|
||||||
|
display.setTextColor(SSD1306_WHITE);// Textfarbe: weiß (OLED kennt nur an/aus)
|
||||||
|
|
||||||
|
// Zeile 1: Status
|
||||||
|
display.setCursor(0, 0); // oben links starten
|
||||||
|
display.println("WLAN OK"); // WLAN verbunden
|
||||||
|
|
||||||
|
// Zeile 2: Label
|
||||||
|
display.setCursor(0, 28); // etwas nach unten (Abstand wegen großer Schrift)
|
||||||
|
display.println("IP:");
|
||||||
|
|
||||||
|
// Zeile 3: IP-Adresse
|
||||||
|
display.setCursor(0, 48); // fast unten im Display
|
||||||
|
display.println(ip); // echte IP vom Router
|
||||||
|
|
||||||
|
display.display(); // alles auf OLED „anzeigen“ (Buffer → Screen)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// Setup: läuft EINMAL beim Start des ESP
|
||||||
|
// -----------------------------------------------------
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Wire.begin(21, 22); // I2C starten (SDA=21, SCL=22)
|
||||||
|
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // OLED starten (Adresse 0x3C Standard)
|
||||||
|
|
||||||
|
// Startbildschirm: WLAN wird verbunden
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(2); // große Schrift für „Verbinde WLAN“
|
||||||
|
display.setCursor(0, 28); // ungefähr Mitte
|
||||||
|
display.println("Verbinde WLAN...");
|
||||||
|
display.display(); // anzeigen
|
||||||
|
|
||||||
|
// WLAN verbinden
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
// warten bis Verbindung steht
|
||||||
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
delay(500); // alle 0.5s prüfen
|
||||||
|
}
|
||||||
|
|
||||||
|
// wenn verbunden → IP holen
|
||||||
|
String ip = WiFi.localIP().toString();
|
||||||
|
|
||||||
|
// IP + Status anzeigen
|
||||||
|
showIP(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// Loop: läuft dauerhaft (hier aktuell NICHT benutzt)
|
||||||
|
// -----------------------------------------------------
|
||||||
|
void loop() {
|
||||||
|
// später: hier kommen Buttons, Webserver, Nachrichten usw.
|
||||||
|
}
|
||||||
44
Namen wechseln lassen (optimiert).txt
Normal file
44
Namen wechseln lassen (optimiert).txt
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
|
||||||
|
Adafruit_SSD1306 display(
|
||||||
|
SCREEN_WIDTH,
|
||||||
|
SCREEN_HEIGHT,
|
||||||
|
&Wire,
|
||||||
|
-1
|
||||||
|
);
|
||||||
|
|
||||||
|
void showName(String name) {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println(name);
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Wire.begin(21, 22);
|
||||||
|
|
||||||
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Display nicht gefunden!");
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
showName("Max");
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
|
showName("Lea");
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
|
showName("Tim");
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue