From 9d3b77de0f6f27e0a194030047d311f6fd233cd8 Mon Sep 17 00:00:00 2001 From: Tilman Date: Tue, 6 Dec 2022 09:38:26 +0100 Subject: [PATCH] Wemos D1 examples --- D1 mini/On_Air/On_Air.ino | 4 ++ D1 mini/blink/blink.ino | 14 +++++ D1 mini/d1_eeprom/d1_eeprom.ino | 93 +++++++++++++++++++++++++++++++++ WS2812/WS2812.ino | 54 +++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 D1 mini/blink/blink.ino create mode 100644 D1 mini/d1_eeprom/d1_eeprom.ino create mode 100644 WS2812/WS2812.ino diff --git a/D1 mini/On_Air/On_Air.ino b/D1 mini/On_Air/On_Air.ino index e8416a3..249a075 100644 --- a/D1 mini/On_Air/On_Air.ino +++ b/D1 mini/On_Air/On_Air.ino @@ -2,6 +2,8 @@ #include +// FIXME BUILTIN_LED muss heißen LED_BUILTIN - https://desertbot.io/blog/d1-mini-blink + const int optocoupler = D2; const char* ssid = "LeWe"; @@ -39,6 +41,8 @@ void setup() { Serial.println(); Serial.print("IP address: "); Serial.println(WiFi.localIP()); + WiFi.setAutoReconnect(true); + WiFi.persistent(true); digitalWrite(BUILTIN_LED, HIGH); server.on("/click", handle_click); diff --git a/D1 mini/blink/blink.ino b/D1 mini/blink/blink.ino new file mode 100644 index 0000000..4e11a66 --- /dev/null +++ b/D1 mini/blink/blink.ino @@ -0,0 +1,14 @@ +// Source: https://desertbot.io/blog/d1-mini-blink + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); // Arduino: turn the LED on (HIGH) + // D1 Mini: turns the LED *off* + delay(1000); // wait for a second + digitalWrite(LED_BUILTIN, LOW); // Arduino: turn the LED off (LOW) + // D1 Mini: turns the LED *on* + delay(1000); // wait for a second +} diff --git a/D1 mini/d1_eeprom/d1_eeprom.ino b/D1 mini/d1_eeprom/d1_eeprom.ino new file mode 100644 index 0000000..3cdb829 --- /dev/null +++ b/D1 mini/d1_eeprom/d1_eeprom.ino @@ -0,0 +1,93 @@ +/* + * https://forum.arduino.cc/t/esp8266-eeprom/631650/10 + * https://docs.arduino.cc/learn/built-in-libraries/eeprom#put + */ + +#include + +using Container = byte[4]; + + + +struct EpData // eine Datensammlung im EEPROM +{ + int kram; + Container container; + bool flagge; + // usw +}; + +Container satzA {'a','b','c','d'}; // beispieldaten +Container satzB {'w','x','y','z'}; // beispieldaten + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +MyObject obj1 {1.111f, 42, "siarp"}; + + + + + +void setup(void) +{ + EEPROM.begin(512); // Um Speicherplatz zu sparen, sollte der Pufferspeicher nicht größer als notwendig initialisiert werden. Die Maximale Größe beträgt 4096. + Serial.begin(9600); + + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + +/* Serial.println(); + Serial.println(); + Serial.println(" Menue"); + Serial.println(" a) schreibt satzA"); + Serial.println(" b) schreibt satzB"); + Serial.println(" p) liest EEPROM und zeigt den Inhalt"); + + Serial.println(); + Serial.println();*/ + +// EEPROM.put(0, obj1); +// EEPROM.commit(); + + MyObject rObj; + EEPROM.get(0, rObj); + + Serial.println("Read custom object from EEPROM:"); + Serial.println(rObj.field1); + Serial.println(rObj.field2); + Serial.println(rObj.name); + +} + + +void loop(void) +{/* + switch(Serial.read()) + { + case 'a': EEPROM.put(offsetof(EpData,container),satzA); + EEPROM.commit(); + Serial.println(" SatzA geschrieben"); + break; + + case 'b': EEPROM.put(offsetof(EpData,container),satzB); + EEPROM.commit(); + Serial.println(" SatzB geschrieben"); + break; + + case 'p': Serial.println(" Satz lesen "); + Container gelesenerSatz; + EEPROM.get(offsetof(EpData,container),gelesenerSatz ); + for(byte g:gelesenerSatz) + { + Serial.print(g); + Serial.print(','); + } + Serial.println(); + break; + }*/ +} diff --git a/WS2812/WS2812.ino b/WS2812/WS2812.ino new file mode 100644 index 0000000..6f45f50 --- /dev/null +++ b/WS2812/WS2812.ino @@ -0,0 +1,54 @@ +#include + +#define PIN D2 +#define NUMPIXELS 1 + +Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); + +void setup() +{ + Serial.begin(9600); + delay(250); + Serial.println("PIXEL"); + + pixels.begin(); // This initializes the NeoPixel library. +} + +void loop() +{ + pixels.setBrightness(20); //die Helligkeit setzen 0 dunkel -> 255 ganz hell + pixels.setPixelColor(0, pixels.Color(255, 255, 255)); + pixels.show(); + delay(1000); + + pixels.setBrightness(80); //die Helligkeit setzen 0 dunkel -> 255 ganz hell + pixels.setPixelColor(0, pixels.Color(255, 255, 255)); + pixels.show(); + delay(1000); + + pixels.setPixelColor(0, pixels.Color(226, 0, 200)); + for (int i = 1; i <= 250; i++) { + pixels.setBrightness(i); + pixels.show(); + delay(20); + } + + pixels.setBrightness(20); + for (int hsv = 0; hsv < 65535; hsv++) { + pixels.setPixelColor(0, pixels.gamma32(pixels.ColorHSV(hsv))); + pixels.show(); + delay(1); + } + + +// // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 +// for (int i = 0; i < 2; i++) { +// for (int j = 0; j < 2; j++) { +// for (int k = 0; k < 2; k++) { +// pixels.setPixelColor(0, pixels.Color(i * 255, j * 255, k * 255)); // Moderately bright green color. +// pixels.show(); // This sends the updated pixel color to the hardware. +// delay(200); // Delay for a period of time (in milliseconds). +// } +// } +// } +}