diff --git a/lab1/.vscode/c_cpp_properties.json b/lab1/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..cea4d3f --- /dev/null +++ b/lab1/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/lab1/.vscode/launch.json b/lab1/.vscode/launch.json new file mode 100644 index 0000000..f7206e6 --- /dev/null +++ b/lab1/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/lviv0/Development/Arduino/Project/lab_1", + "program": "c:/Users/lviv0/Development/Arduino/Project/lab_1/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/lab1/.vscode/settings.json b/lab1/.vscode/settings.json new file mode 100644 index 0000000..c9e66f1 --- /dev/null +++ b/lab1/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/lab1/delete.html b/lab1/delete.html new file mode 100644 index 0000000..ee31af5 --- /dev/null +++ b/lab1/delete.html @@ -0,0 +1,101 @@ + + + + + + ESP32 LED Control + + + + +

ESP32 LED Control

+ + + +
+
+
+
+
+ + \ No newline at end of file diff --git a/lab1/lab_1.ino b/lab1/lab_1.ino new file mode 100644 index 0000000..49e7e62 --- /dev/null +++ b/lab1/lab_1.ino @@ -0,0 +1,55 @@ +#include +#include "pins.h" +#include "web_server.h" +#include "led_lightning.h" + +uint32_t interval = 100; + +bool lastButtonState = HIGH; +uint32_t lastDebounceTime = 0; +uint32_t debounceDelay = 50; +bool startAlgorithm = false; + +void increaseInterval() +{ + interval += 100; + Serial.println("Interval increased: " + String(interval) + " ms"); +} + +void initPins() +{ + pinMode(buttonPin, INPUT); + for (int i = 0; i < ledCount; i++) + { + pinMode(leds[i], OUTPUT); + digitalWrite(leds[i], LOW); + } +} + +void IRAM_ATTR handleButtonPress() +{ + uint32_t currentMillis = millis(); + if ((currentMillis - lastDebounceTime) > debounceDelay) + { + increaseInterval(); + lastDebounceTime = currentMillis; + } +} + +void setup() +{ + Serial.begin(115200); + initPins(); + initWebServer(); + attachInterrupt(digitalPinToInterrupt(buttonPin), handleButtonPress, FALLING); +} + +void loop() +{ + server.handleClient(); + if (startAlgorithm) + { + ledLighting(interval); + } +} + diff --git a/lab1/led_lightning.h b/lab1/led_lightning.h new file mode 100644 index 0000000..3f66100 --- /dev/null +++ b/lab1/led_lightning.h @@ -0,0 +1,21 @@ +#ifndef LED_LIGHTNING_H +#define LED_LIGHTNING_H +#include "pins.h" + +uint32_t previousMillis = 0; +uint8_t currentLed = 0; + +void ledLighting(uint32_t ledInterval) +{ + uint32_t currentMillis = millis(); + + if ((currentMillis - previousMillis) >= ledInterval) + { + previousMillis = currentMillis; + digitalWrite(leds[currentLed], LOW); + currentLed = (currentLed + 1) % ledCount; + digitalWrite(leds[currentLed], HIGH); + } +} + +#endif // LED_LIGHTNING_H \ No newline at end of file diff --git a/lab1/pins.h b/lab1/pins.h new file mode 100644 index 0000000..9f9caf5 --- /dev/null +++ b/lab1/pins.h @@ -0,0 +1,8 @@ +#ifndef PINS_H +#define PINS_H + +const uint8_t buttonPin = 13; +const uint8_t leds[] = {2, 4, 5}; +const int ledCount = sizeof(leds) / sizeof(leds[0]); + +#endif // PINS_H diff --git a/lab1/schema.png b/lab1/schema.png new file mode 100644 index 0000000..7b6f950 Binary files /dev/null and b/lab1/schema.png differ diff --git a/lab1/web_server.h b/lab1/web_server.h new file mode 100644 index 0000000..c0cc71b --- /dev/null +++ b/lab1/web_server.h @@ -0,0 +1,125 @@ +#ifndef WEB_SERVER_H +#define WEB_SERVER_H + +#include +#include + +extern void startAlgorithm1(); +extern void startAlgorithm2(); +extern String getLedState(); + +WebServer server(80); + +const char* ssid = "ESP32"; +const char* password = "12345678"; + +void handleRoot() { + server.send(200, "text/html", R"rawliteral( + + + + + + ESP32 LED Control + + + + +

ESP32 LED Control

+ + + +
+
+
+
+
+ + + )rawliteral"); +} + +void handleAlgo1() { + startAlgorithm1(); + server.send(200, "text/plain", "Algorithm 1 started"); +} + +void handleAlgo2() { + startAlgorithm2(); + server.send(200, "text/plain", "Algorithm 2 started"); +} + +void handleLedState() { + server.send(200, "application/json", getLedState()); +} + +void initWebServer() { + WiFi.softAP(ssid, password); + Serial.println("WiFi AP launched!"); + Serial.println(WiFi.softAPIP()); + + server.on("/", HTTP_GET, handleRoot); + server.on("/algo1", HTTP_GET, handleAlgo1); + server.on("/algo2", HTTP_GET, handleAlgo2); + server.on("/led_state", HTTP_GET, handleLedState); + server.begin(); +} + +#endif // WEB_SERVER_H