6 changed files with 127 additions and 0 deletions
@ -0,0 +1,5 @@ |
|||||
|
.pio |
||||
|
.vscode/.browse.c_cpp.db* |
||||
|
.vscode/c_cpp_properties.json |
||||
|
.vscode/launch.json |
||||
|
.vscode/ipch |
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846 |
||||
|
// for the documentation about the extensions.json format |
||||
|
"recommendations": [ |
||||
|
"platformio.platformio-ide" |
||||
|
], |
||||
|
"unwantedRecommendations": [ |
||||
|
"ms-vscode.cpptools-extension-pack" |
||||
|
] |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>Ovládání LED pásku</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h1>Ovládání LED pásku</h1> |
||||
|
<form id="ledForm"> |
||||
|
<label for="barvaLed">Barva LED:</label> |
||||
|
<input type="color" name="barvaLed" |
||||
|
id="barvaLed" value="#FF0000"> |
||||
|
<input type="submit" value="Nastavit"> |
||||
|
</form> |
||||
|
<script> |
||||
|
//nalezneme elements s id ledForm a nastavíme odposlech na "submit" který po aktivaci aktivuje funkci |
||||
|
document.getElementById("ledForm").addEventListener("submit", function(event){ |
||||
|
event.preventDefault(); //nepřesměruje stránku -> kod bude pokračovat |
||||
|
var barva = document.getElementById("barvaLed").value; //získání hodnoty z formuláře |
||||
|
var xhr = new XMLHttpRequest(); //vytvoření nového požadavku |
||||
|
xhr.open("POST","/nastavit",true); //nstavení odkazu kam budeme posílat požadavky |
||||
|
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); //nastavení hlavičky pro snažší odeslání |
||||
|
xhr.send("barva="+barva); |
||||
|
}) |
||||
|
</script> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,20 @@ |
|||||
|
; PlatformIO Project Configuration File |
||||
|
; |
||||
|
; Build options: build flags, source filter |
||||
|
; Upload options: custom upload port, speed and extra flags |
||||
|
; Library options: dependencies, extra library storages |
||||
|
; Advanced options: extra scripting |
||||
|
; |
||||
|
; Please visit documentation for the other options and examples |
||||
|
; https://docs.platformio.org/page/projectconf.html |
||||
|
|
||||
|
[env:esp32dev] |
||||
|
platform = espressif32 |
||||
|
board = esp32dev |
||||
|
framework = arduino |
||||
|
monitor_speed = 115200 |
||||
|
board_build.filesystem = littlefs |
||||
|
lib_deps = |
||||
|
fastled/FastLED@^3.6.0 |
||||
|
ESP32Async/AsyncTCP |
||||
|
ESP32Async/ESPAsyncWebServer |
@ -0,0 +1,53 @@ |
|||||
|
#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() { |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
|
||||
|
This directory is intended for PlatformIO Test Runner and project tests. |
||||
|
|
||||
|
Unit Testing is a software testing method by which individual units of |
||||
|
source code, sets of one or more MCU program modules together with associated |
||||
|
control data, usage procedures, and operating procedures, are tested to |
||||
|
determine whether they are fit for use. Unit testing finds problems early |
||||
|
in the development cycle. |
||||
|
|
||||
|
More information about PlatformIO Unit Testing: |
||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html |
Loading…
Reference in new issue