#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= "Banda LED WS2812Selecteaza
animatia ta favorita:
Modifica luminozitatea maxima a
animatiilor
";
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=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();
}