Wemos D1 examples
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* https://forum.arduino.cc/t/esp8266-eeprom/631650/10
|
||||
* https://docs.arduino.cc/learn/built-in-libraries/eeprom#put
|
||||
*/
|
||||
|
||||
#include <EEPROM.h>
|
||||
|
||||
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;
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user