#include "Freenove_WS2812_Lib_for_ESP32.h" #include "WiFi.h" #include "WiFiClient.h" #include "WebServer.h" #include "ESPmDNS.h" #include "BlynkSimpleEsp32.h" #include "ESPmDNS.h" #include "WiFiUdp.h" #include "ArduinoOTA.h" #define LEDS_COUNT 30 #define LEDS_PIN 2 #define CHANNEL 0 #define Lightlevel1 250 #define LightLevelDecrease 50 #define BLYNK_PRINT Serial TaskHandle_t Task1; int state=1; int white=0; int customcolorswitch=0; char auth[] = "****";//inlocuiti cu codul dvs. Blynk int customred=0,customgreen=0,customblue=0; int timedelay=50; int Brightnesssteps=50; int animation = 0; int Brightness=0; int currentlevel = Lightlevel1; const char* ssid = "****"; //numele retelei dvs de wifi const char* password = "*****a"; // parola retelei dvs de wifi const char* httpHomepage= "<head><title>Banda LED WS2812</title></head><body><p>Selecteaza animatia ta favorita:</p><form action='/animation1'><input type='submit' value='Animatia 1' /></form><form action='/animation2'><input type='submit' value='Animatia 2' /></form><form action='/animation3'><input type='submit' value='Animatia 3' /></form><form action='/animationoff'><input type='submit' value='Off' /></form><p>Modifica luminozitatea maxima a animatiilor</p><form action='/brightnessup'><input type='submit' value='+'></form><form action='/brightnessdown'><input type='submit' value='-'></form>"; WebServer server(80); BLYNK_WRITE(V0) { customred= param.asInt(); } BLYNK_WRITE(V1) { customgreen= param.asInt(); } BLYNK_WRITE(V2) { customblue= param.asInt(); } BLYNK_WRITE(V3) { timedelay= param.asInt(); } BLYNK_WRITE(V4) { animation = param.asInt(); } BLYNK_WRITE(V5) { Brightness= param.asInt(); } BLYNK_WRITE(V6) { customcolorswitch= param.asInt(); } BLYNK_WRITE(V7) { state= param.asInt(); } Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL, TYPE_GRB); u8 m_color[5][3] = { {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 255}, {0, 0, 0} }; void Task1code( void * parameter) { while(true){ if(customcolorswitch==0&&white==0&&state==1){ if(animation==0){ Serial.println("animation1"); for (int j = 0; j < 255; j += 2) { for (int i = 0; i < LEDS_COUNT; i++) { strip.setLedColorData(i, strip.Wheel((i * 256 / LEDS_COUNT + j) & 255)); } strip.show(); delay(timedelay); } } if(animation==1){ Serial.println("animation2"); for (int j = 0; j < 5; j++) { for (int i = 0; i < LEDS_COUNT; i++) { strip.setLedColorData(i, m_color[j][0], m_color[j][1], m_color[j][2]); strip.show(); delay(timedelay); } delay(timedelay); } } //aici puteti adauga o noua animatie } if(customcolorswitch==1&&white==0&&state==1){ for(int i=0;i<LEDS_COUNT;i++){ strip.setLedColorData(i, customred,customgreen,customblue); } strip.show(); } if(white==1) for(int i=0;i<LEDS_COUNT;i++) {strip.setLedColorData(i,m_color[3][0], m_color[3][1], m_color[3][2]);} strip.show(); if(state==0) for(int i=0;i<LEDS_COUNT;i++) {strip.setLedColor(i,m_color[4][0], m_color[4][1], m_color[4][2]);} } } void handleNotFound(){ } void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); Blynk.begin("*****", ssid, password);//inlocuiti cu codul dvs blynk if (MDNS.begin("esp32")) { Serial.println("MDNS responder started"); } server.onNotFound(handleNotFound); server.on("/", []() { server.send(200, "text/html", httpHomepage); }); server.on("/animation1", []() { server.send(200, "text/html", httpHomepage); animation=0; Serial.print("animation has changed to "); Serial.println(animation); }); server.on("/animation2", []() { server.send(200, "text/html", httpHomepage); animation=1; Serial.print("animation has changed to "); Serial.println(animation); }); server.on("/animation3", []() { server.send(200, "text/html", httpHomepage); animation=2; Serial.print("animation has changed to "); Serial.println(animation); }); server.on("/animationoff", []() { server.send(200, "text/html", httpHomepage); animation=9999; Serial.print("animation has changed to "); Serial.println(animation); }); server.on("/brightnessup", []() { server.send(200, "text/html", httpHomepage); animation=1; if(255-Brightness<=Brightnesssteps) Brightness=Brightness+Brightnesssteps; else Brightness=255; Serial.print("Brightness seted to:"); Serial.println(Brightness); }); server.on("/brightnessdown", []() { server.send(200, "text/html", httpHomepage); animation=1; if(Brightness>=Brightnesssteps) Brightness=Brightness-Brightnesssteps; else Brightness=0; Serial.print("Brightness seted to:"); Serial.println(Brightness); }); server.begin(); Serial.println("HTTP server started"); strip.begin(); strip.setBrightness(254); xTaskCreatePinnedToCore( Task1code, /* Function to implement the task */ "Task1", /* Name of the task */ 10000, /* Stack size in words */ NULL, /* Task input parameter */ 0, /* Priority of the task */ &Task1, /* Task handle. */ 0); /* Core where the task should run */ ArduinoOTA .onStart([]() { String type; if (ArduinoOTA.getCommand() == U_FLASH) type = "sketch"; else // U_SPIFFS type = "filesystem"; // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() Serial.println("Start updating " + type); }) .onEnd([]() { Serial.println("\nEnd"); }) .onProgress([](unsigned int progress, unsigned int total) { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }) .onError([](ota_error_t error) { Serial.printf("Error[%u]: ", error); if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); ArduinoOTA.begin(); } void loop() { ArduinoOTA.handle(); server.handleClient(); strip.setBrightness(Brightness); Blynk.run(); }