#include #include #include // Wi-Fi credentials const char* ssid = "MAKERSPACE"; const char* password = "12345678"; // LED setup #define LED_PIN 10 #define LED_COUNT 30 Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); WebServer server(80); // Current state int brightness = 50; int r = 255, g = 0, b = 0; String currentPattern = "solid"; void setup() { Serial.begin(115200); strip.begin(); strip.setBrightness(brightness); strip.show(); // Connect to Wi-Fi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected to WiFi"); Serial.println(WiFi.localIP()); // Setup web routes server.on("/", handleRoot); server.on("/color", handleColor); server.on("/pattern", handlePattern); server.on("/brightness", handleBrightness); server.begin(); } void loop() { server.handleClient(); updateLEDs(); } void handleRoot() { String html = R"(

LED Control Panel

Color

Brightness

Patterns

)"; server.send(200, "text/html", html); } void handleColor() { r = server.arg("r").toInt(); g = server.arg("g").toInt(); b = server.arg("b").toInt(); server.send(200, "text/plain", "OK"); } void handlePattern() { currentPattern = server.arg("name"); server.send(200, "text/plain", "OK"); } void handleBrightness() { brightness = server.arg("value").toInt(); strip.setBrightness(brightness); server.send(200, "text/plain", "OK"); } void updateLEDs() { if (currentPattern == "solid") { for(int i = 0; i < LED_COUNT; i++) { strip.setPixelColor(i, strip.Color(r, g, b)); } } else if (currentPattern == "rainbow") { rainbowCycle(); } else if (currentPattern == "pulse") { pulseEffect(); } else if (currentPattern == "wave") { waveEffect(); } strip.show(); } // Add these pattern functions at the end: void rainbowCycle() { static uint16_t j = 0; for(int i = 0; i < LED_COUNT; i++) { int pixelHue = (i * 65536L / LED_COUNT + j * 256) % 65536; strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); } j = (j + 1) % 256; } void pulseEffect() { static uint8_t pulse = 0; static bool increasing = true; if (increasing) { pulse++; if (pulse >= 255) increasing = false; } else { pulse--; if (pulse <= 0) increasing = true; } for(int i = 0; i < LED_COUNT; i++) { strip.setPixelColor(i, strip.Color( (r * pulse) / 255, (g * pulse) / 255, (b * pulse) / 255 )); } } void waveEffect() { static uint8_t pos = 0; for(int i = 0; i < LED_COUNT; i++) { int brightness = sin(((i + pos) * 3.14159) / 8) * 127 + 128; strip.setPixelColor(i, strip.Color( (r * brightness) / 255, (g * brightness) / 255, (b * brightness) / 255 )); } pos = (pos + 1) % LED_COUNT; }