You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
#include <Arduino.h>
|
|
#include <LittleFS.h>
|
|
#include <WiFi.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
#include <FastLED.h>
|
|
|
|
const char* ssid = "tksteti";
|
|
const char* password = "ProsimTeNevim";
|
|
AsyncWebServer server(80);
|
|
#define NUM_LEDS 4
|
|
#define DATA_PIN 12
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
void handleNastavit(AsyncWebServerRequest *request) {
|
|
if (request->hasParam("barva",true)) {
|
|
String barva = request->getParam("barva",true)->value();
|
|
long barvaLong = strtol(barva.substring(1,7).c_str(),NULL,16);
|
|
int r = (barvaLong >> 16) & 0xFF;
|
|
int g = (barvaLong >> 8) & 0xFF;
|
|
int b = barvaLong & 0xFF;
|
|
|
|
for (int i = 0; i < NUM_LEDS; i++) {
|
|
leds[i] = CRGB(r,g,b);
|
|
}
|
|
FastLED.show();
|
|
request->send(200,"text/plain","OK");
|
|
} else {
|
|
request->send(400,"text/plain","Bad Request");
|
|
}
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
if(!LittleFS.begin(true)){
|
|
Serial.println("Chyba při zavádění (mounting) LittleFS");
|
|
return;
|
|
}
|
|
WiFi.begin(ssid,password);
|
|
while(WiFi.status() != WL_CONNECTED) {
|
|
Serial.print(".");
|
|
delay(50);
|
|
}
|
|
Serial.println("Připojeno k WiFi");
|
|
FastLED.addLeds<WS2812B,DATA_PIN,GRB>(leds,NUM_LEDS);
|
|
server.on("/",HTTP_GET,[](AsyncWebServerRequest *request){
|
|
request ->send(LittleFS,"/index.html","text/html");
|
|
});
|
|
server.on("/nastavit",HTTP_POST,handleNastavit);
|
|
server.begin();
|
|
}
|
|
|
|
void loop() {
|
|
}
|