Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lab1/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions lab1/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
59 changes: 59 additions & 0 deletions lab1/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
101 changes: 101 additions & 0 deletions lab1/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ESP32 LED Control</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f4f4f9;
}
h1 {
color: #333;
}
button {
background-color: #007BFF;
color: white;
border: none;
padding: 15px 32px;
margin: 10px;
font-size: 16px;
cursor: pointer;
border-radius: 8px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
.led-container {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 20px;
}
.led {
width: 50px;
height: 50px;
background-color: gray;
border-radius: 5px;
display: inline-block;
transition: background-color 0.3s;
}
</style>
<script>
const led1 = document.getElementById('led1');
const led2 = document.getElementById('led2');
const led3 = document.getElementById('led3');

let currentLED;

function ledLight(led) {
led1.style.backgroundColor = 'gray';
led2.style.backgroundColor = 'gray';
led3.style.backgroundColor = 'gray';

switch (led) {
case 1:
led1.style.backgroundColor = 'yellow';
break;
case 2:
led2.style.backgroundColor = 'green';
break;
case 3:
led3.style.backgroundColor = 'red';
break;
}
}

function sendCommand(command) {
fetch('/' + command)
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}

function updateLEDs() {
fetch('/led_state')
.then(response => response.text())
.then(data => {
currentLED = data;
console.log(data);
})
.catch(error => console.error('Error:', error));
}

setInterval(updateLEDs, 100);
</script>
</head>
<body>
<h1>ESP32 LED Control</h1>
<button onclick="sendCommand('algo1')">Algorythm 1</button>
<button onclick="sendCommand('algo2')">Algorythm 2</button>

<div class="led-container">
<div id="led1" class="led"></div>
<div id="led2" class="led"></div>
<div id="led3" class="led"></div>
</div>
</body>
</html>
55 changes: 55 additions & 0 deletions lab1/lab_1.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <Arduino.h>
#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);
}
}

21 changes: 21 additions & 0 deletions lab1/led_lightning.h
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lab1/pins.h
Original file line number Diff line number Diff line change
@@ -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
Binary file added lab1/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading