#include #include #include #define PIN_NEO_PIXEL D3 #define NUM_PIXELS 1 Adafruit_NeoPixel strip(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800); // Replace with your network credentials const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASSWORD"; WebServer server(80); int sliderValue = 50; // initial slider value bool ledOn = false; // initialize led off and store momentary led status bool stateChanged = true; // controll varaibel if the led turned on/off uint8_t brightnessValue() { if (!ledOn) { return 0; } int limit = constrain(sliderValue, 0, 100); // set boundaries for the sliederValue from 0 to 100 return (uint8_t)map(limit, 0, 100, 0, 255); // map limited slider value to the possible brightness values (0 to 255) } void updateNeoPixel() { uint8_t level = brightnessValue(); strip.setBrightness(level); strip.setPixelColor(0, strip.Color(255, 220, 0)); strip.show(); stateChanged = false; } void handleRoot() { String initialStateText = ledOn ? "LED: on" : "LED: off"; String html = R"rawliteral( ESP32 Web Interface

ESP32C3 Control Panel

Helligkeit: )rawliteral" + String(sliderValue) + R"rawliteral(%



)rawliteral" + initialStateText + R"rawliteral(

)rawliteral"; server.send(200, "text/html", html); } void handleSlider() { if (server.hasArg("value")) { sliderValue = constrain(server.arg("value").toInt(), 0, 100); stateChanged = true; Serial.println("Slider set to: " + String(sliderValue) + "%"); server.send(200, "text/plain", "Slider value set"); } else { server.send(400, "text/plain", "Missing value"); } } void handleButton() { ledOn = !ledOn; stateChanged = true; String statusText = ledOn ? "LED: on" : "LED: off"; Serial.println(statusText); server.send(200, "text/plain", statusText); } void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.println("Connecting to WiFi..."); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected! IP address: "); Serial.println(WiFi.localIP()); server.on("/", handleRoot); server.on("/slider", handleSlider); server.on("/button", handleButton); server.begin(); Serial.println("HTTP server started"); strip.begin(); strip.setBrightness(255); updateNeoPixel(); } void loop() { server.handleClient(); if (stateChanged) { updateNeoPixel(); } }