Wemos D1 examples
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
|
||||||
|
|
||||||
|
// FIXME BUILTIN_LED muss heißen LED_BUILTIN - https://desertbot.io/blog/d1-mini-blink
|
||||||
|
|
||||||
const int optocoupler = D2;
|
const int optocoupler = D2;
|
||||||
|
|
||||||
const char* ssid = "LeWe";
|
const char* ssid = "LeWe";
|
||||||
@@ -39,6 +41,8 @@ void setup() {
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.print("IP address: ");
|
Serial.print("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
WiFi.setAutoReconnect(true);
|
||||||
|
WiFi.persistent(true);
|
||||||
digitalWrite(BUILTIN_LED, HIGH);
|
digitalWrite(BUILTIN_LED, HIGH);
|
||||||
|
|
||||||
server.on("/click", handle_click);
|
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;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#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).
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user