#include #include #include #include #define LED_PIN 4 #define NUM_LEDS 60 #define COLOR_ORDER GRB #define LED_TYPE WS2812 #define EEPROM_SIZE 5 #define WIFI_TIMEOUT 180000 // 3 минуты CRGB leds[NUM_LEDS]; WebServer server(80); const char* ssid = "Your_SSID"; const char* password = "Your_PASSWORD"; uint8_t currentMode = 1; // 0: статический, 1: переливание, 2: мерцание, 3: бегущая радуга uint8_t red = 255, green = 255, blue = 255; bool wifiActive = true; unsigned long startTime; void setup() { Serial.begin(115200); FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); FastLED.setBrightness(255); EEPROM.begin(EEPROM_SIZE); loadSettings(); startTime = millis(); WiFi.begin(ssid, password); Serial.println("Подключение к WiFi..."); } void loop() { // Проверка таймаута WiFi if (wifiActive && millis() - startTime > WIFI_TIMEOUT && WiFi.status() != WL_CONNECTED) { WiFi.disconnect(true); WiFi.mode(WIFI_OFF); wifiActive = false; Serial.println("WiFi отключен по таймауту"); } if (wifiActive && WiFi.status() == WL_CONNECTED) { server.handleClient(); } updateLEDs(); FastLED.show(); delay(20); } void handleRoot() { String html = R"=====( Управление RGB лентой

Управление RGB лентой

Статический цвет

Красный:

Зеленый:

Синий:

Режимы работы

)====="; server.send(200, "text/html", html); } void handleSetColor() { if (server.hasArg("r") && server.hasArg("g") && server.hasArg("b")) { red = server.arg("r").toInt(); green = server.arg("g").toInt(); blue = server.arg("b").toInt(); if (currentMode == 0) { fill_solid(leds, NUM_LEDS, CRGB(red, green, blue)); } saveSettings(); server.send(200, "text/plain", "OK"); } } void handleSetMode() { if (server.hasArg("mode")) { currentMode = server.arg("mode").toInt(); saveSettings(); server.send(200, "text/plain", "OK"); } } void loadSettings() { currentMode = EEPROM.read(0); red = EEPROM.read(1); green = EEPROM.read(2); blue = EEPROM.read(3); // Проверка на первый запуск if (red == 0 && green == 0 && blue == 0) { red = green = blue = 255; } } void saveSettings() { EEPROM.write(0, currentMode); EEPROM.write(1, red); EEPROM.write(2, green); EEPROM.write(3, blue); EEPROM.commit(); } void startWebServer() { server.on("/", handleRoot); server.on("/setcolor", handleSetColor); server.on("/setmode", handleSetMode); server.begin(); Serial.println("HTTP сервер запущен"); } void updateLEDs() { static unsigned long prevUpdate = 0; static uint8_t hue = 0; static uint8_t pos = 0; switch (currentMode) { case 0: // Статический цвет fill_solid(leds, NUM_LEDS, CRGB(red, green, blue)); break; case 1: // Плавное переливание if (millis() - prevUpdate > 30) { prevUpdate = millis(); fill_solid(leds, NUM_LEDS, CHSV(hue++, 255, 255)); } break; case 2: // Мерцание if (millis() - prevUpdate > 100) { prevUpdate = millis(); fadeToBlackBy(leds, NUM_LEDS, 50); leds[random16(NUM_LEDS)] = CRGB(red, green, blue); } break; case 3: // Бегущая радуга (доп режим) if (millis() - prevUpdate > 40) { prevUpdate = millis(); for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CHSV((i * 5 + pos) % 256, 255, 255); } pos += 2; } break; } } void checkWiFiConnection() { if (WiFi.status() == WL_CONNECTED && !serverStarted) { Serial.print("Подключено! IP: "); Serial.println(WiFi.localIP()); startWebServer(); serverStarted = true; } }