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
150 changes: 150 additions & 0 deletions mc_labs/mc_lab_01/Panechko_Taras_Lab_1/lab.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char* ssid = "Galaxy S20 FE 5G";
const char* password = "0985211834";

ESP8266WebServer server(80);

const int ledPins[] = {13, 0, 2}; // LEDs on pins 13, 0, 2
const int buttonPin = 15; // Button on pin 15

const int ledInterval = 500; // Time between LED changes
const int debounceTime = 50; // Button debounce time
const int doubleClickTime = 300; // Time for double click

int currentLedIndex = 0;
bool reverseDirection = false;
bool isRunning = false;
bool buttonIsPressed = false;

unsigned long lastDebounce = 0;
unsigned long lastClick = 0;
unsigned long lastWebClick = 0;

int clickCount = 0;
int webClickCount = 0;

void setup() {
WiFi.begin(ssid, password);
Serial.begin(115200);

while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}

Serial.println("\nIP Address: " + WiFi.localIP().toString());

pinMode(buttonPin, INPUT_PULLUP);
for (int ledPin : ledPins) {
pinMode(ledPin, OUTPUT);
}

server.on("/", handleWebPage);
server.on("/click", handleButtonClick);
server.begin();
}

void loop() {
server.handleClient();
handleButtonInput();
handleDoubleClick();
updateLeds();
}

void handleWebPage() {
String html = "<html><head><style>body {
display: flex;
flex-direction: column;
align-items: center;
font-family: sans-serif; }</style>
</head><body><h1>LED Control</h1>
<button onclick=\"fetch('/click')\">Click</button>
</body></html>";
server.send(200, "text/html", html);
}

void handleButtonClick() {
unsigned long currentTime = millis();

if (currentTime - lastWebClick < doubleClickTime) {
webClickCount++;
} else {
webClickCount = 1;
}
lastWebClick = currentTime;

if (webClickCount == 2) {
isRunning = !isRunning;
if (isRunning) {
reverseDirection = !reverseDirection;
Serial.println("Direction changed (Web)");
}
webClickCount = 0;
}
server.send(200, "text/plain", "OK");
}

void handleButtonInput() {
unsigned long currentTime = millis();
int buttonState = digitalRead(buttonPin);
static bool lastButtonState = HIGH;

if (buttonState != lastButtonState) {
lastDebounce = currentTime;
lastButtonState = buttonState;
}

if ((currentTime - lastDebounce) > debounceTime) {
if (buttonState == LOW && !buttonIsPressed) {
buttonIsPressed = true;
if (currentTime - lastClick < doubleClickTime) {
clickCount++;
} else {
clickCount = 1;
}
lastClick = currentTime;
lastButtonState = HIGH;
} else if (buttonState == HIGH && buttonIsPressed) {
buttonIsPressed = false;
}
}
}

void handleDoubleClick() {
if (clickCount == 2) {
isRunning = !isRunning;
clickCount = 0;
if (isRunning) {
reverseDirection = !reverseDirection;
Serial.println("Direction changed (Button)");
}
}
}

void updateLeds() {
if (!isRunning) {
for (int ledPin : ledPins) {
digitalWrite(ledPin, LOW);
}
return;
}

unsigned long currentTime = millis();
static unsigned long lastLedChange = 0;

if (currentTime - lastLedChange > ledInterval) {
lastLedChange = currentTime;

digitalWrite(ledPins[currentLedIndex], LOW);

if (reverseDirection) {
currentLedIndex = (currentLedIndex - 1 + 3) % 3;
} else {
currentLedIndex = (currentLedIndex + 1) % 3;
}

digitalWrite(ledPins[currentLedIndex], HIGH);
}
}
Binary file added mc_labs/mc_lab_01/Panechko_Taras_Lab_1/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions mc_labs/mc_lab_02/Panechko_Taras_lab_02/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
/.idea
Empty file.
46 changes: 46 additions & 0 deletions mc_labs/mc_lab_02/Panechko_Taras_lab_02/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into the executable file.

The source code of each library should be placed in a separate directory
("lib/your_library_name/[Code]").

For example, see the structure of the following example libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

The PlatformIO Library Dependency Finder will find automatically dependent
libraries by scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading