WEBSERVER_LED_CONTROL/WEBSERVER_LED_CONTROL.ino
2021-04-12 23:31:40 +02:00

70 lines
1.2 KiB
C++

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiManager.h>
#include <FastLED.h>
// LED count and control pin
#define NUM_LEDS 8
#define DATA_PIN D3
// LED array
CRGB leds[NUM_LEDS];
// Web server
ESP8266WebServer server(80);
void setup() {
// Initialize onboard LED
pinMode(LED_BUILTIN, OUTPUT);
// Initialize Wifi, start AP if no saved Wifi in range
WiFiManager wifiManager;
wifiManager.autoConnect("WEMOS D1 mini pro");
// Initialize LEDs
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
// Define web server Handlers
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
// Start webserver
server.begin();
}
void loop() {
server.handleClient();
}
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266!");
}
void handleNotFound() {
server.send(404, "text/plain", "404 File Not Found");
blinkLEDs();
}
void blinkLEDs(){
digitalWrite(LED_BUILTIN, LOW);
for(int i=0;i<8;i++){
leds[i] = CRGB::Red;
FastLED.show();
delay(20);
}
delay(500);
for(int i=0;i<8;i++){
leds[i] = CRGB::Black;
FastLED.show();
delay(20);
}
digitalWrite(LED_BUILTIN, HIGH);
}