diff --git a/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_LED.ino b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_LED.ino new file mode 100644 index 0000000..f8e8a5f --- /dev/null +++ b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_LED.ino @@ -0,0 +1,84 @@ +#define LED1_PIN 0 +#define LED2_PIN 14 +#define LED3_PIN 13 + +#define BUTTON_PIN 12 + +extern bool isBlinking; +extern unsigned long prevMillis; +extern const int blinkInterval; +extern unsigned long timerStart; +extern bool timerActive; +extern int ledState; +extern int pauseState; +extern int ledCount; +extern int timer; + +int stepState = 0; + +void initLEDs() { + pinMode(LED1_PIN, OUTPUT); + pinMode(LED2_PIN, OUTPUT); + pinMode(LED3_PIN, OUTPUT); +} + +void updateLEDs() { + if (digitalRead(BUTTON_PIN) == LOW && isBlinking) { + isBlinking = false; + timerActive = true; + timerStart = millis(); + pauseState = getActiveLed(); + Serial.println("Button pressed, pausing LEDs for 15 sec"); + } + + if (timerActive && millis() - timerStart >= timer) { + isBlinking = true; + timerActive = false; + Serial.println("15 seconds passed, resuming blinking"); + } + + if (isBlinking) { + unsigned long currentMillis = millis(); + if (currentMillis - prevMillis >= blinkInterval) { + prevMillis = currentMillis; + + digitalWrite(LED1_PIN, LOW); + digitalWrite(LED2_PIN, LOW); + digitalWrite(LED3_PIN, LOW); + + int currentLed = getCurrentLed(); + switch (currentLed) { + case 0: digitalWrite(LED1_PIN, HIGH); break; + case 1: digitalWrite(LED2_PIN, HIGH); break; + case 2: digitalWrite(LED3_PIN, HIGH); break; + } + + stepState++; + if (stepState > 2) { + stepState = 0; + ledState = (ledState + 1) % ledCount; + } + } + } else { + digitalWrite(LED1_PIN, pauseState == 0 ? HIGH : LOW); + digitalWrite(LED2_PIN, pauseState == 1 ? HIGH : LOW); + digitalWrite(LED3_PIN, pauseState == 2 ? HIGH : LOW); + } +} + +int getCurrentLed() { + if (stepState == 0) { + return ledState; + } else if (stepState == 1) { + if (ledState == 0) return 2; + if (ledState == 1) return 0; + if (ledState == 2) return 1; + } else if (stepState == 2) { + return ledState; + } + return ledState; +} + +int getActiveLed() { + return getCurrentLed(); +} diff --git a/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_laboratory.ino b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_laboratory.ino new file mode 100644 index 0000000..76672a2 --- /dev/null +++ b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_laboratory.ino @@ -0,0 +1,48 @@ +#include +#include + +#define BUTTON_PIN 12 + +bool isBlinking = true; +unsigned long prevMillis = 0; +const int blinkInterval = 500; +unsigned long timerStart = 0; +bool timerActive = false; +int ledState = 0; +int pauseState = LOW; +int ledCount = 3; +int timer = 15000; + +const char* ssid = "netis"; +const char* password = "password"; + +ESP8266WebServer server(80); + +void updateLEDs(); +void web(); +void webToggle(); +void initLEDs(); + +void setup() { + Serial.begin(115200); + pinMode(BUTTON_PIN, INPUT_PULLUP); + + WiFi.begin(ssid, password); + Serial.print("Connecting to WiFi..."); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("\nConnected! IP: " + WiFi.localIP().toString()); + + initLEDs(); + + server.on("/", web); + server.on("/toggle", webToggle); + server.begin(); +} + +void loop() { + server.handleClient(); + updateLEDs(); +} diff --git a/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_web_server.ino b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_web_server.ino new file mode 100644 index 0000000..2d99a52 --- /dev/null +++ b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/1_web_server.ino @@ -0,0 +1,51 @@ +#include + +extern ESP8266WebServer server; + +extern bool isBlinking; +extern unsigned long timerStart; +extern bool timerActive; +extern int pauseState; +extern int ledState; +extern int ledCount; +extern int timer; + +void web() { + String html = "\ + \ + \ + \ + \ + \ + \ +

ESP Pushbutton Web Server

\ + \ + \ + "; + + server.send(200, "text/html", html); +} + +void webToggle() { + isBlinking = !isBlinking; + + if (!isBlinking) { + timerActive = true; + timerStart = millis(); + pauseState = ledState; + + Serial.println("Web button pressed, pausing LEDs for 15 sec"); + } + + server.send(200, "text/plain", "Toggled"); +} diff --git a/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/data/image.png b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/data/image.png new file mode 100644 index 0000000..21f01f9 Binary files /dev/null and b/mc_labs/mc_lab_01/Staryk_Vitalii_Lab_01/data/image.png differ diff --git "a/mc_labs/mc_lab_01/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2261(MK).pdf" "b/mc_labs/mc_lab_01/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2261(MK).pdf" deleted file mode 100644 index 5399010..0000000 Binary files "a/mc_labs/mc_lab_01/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2261(MK).pdf" and /dev/null differ diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_ESP.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_ESP.ino new file mode 100644 index 0000000..65f3044 --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_ESP.ino @@ -0,0 +1,49 @@ +#include +#include + +const int CMD_STOP_L = 65; +const int CMD_STOP_M = 66; + +const char* ssid = "iPhone de Vitaliy"; +const char* password = "iphone14"; + +ESP8266WebServer server(80); + +const int leds[] = {2, 13, 14}; +const int numLeds = sizeof(leds) / sizeof(leds[0]); +const int buttonPin = 16; +const int ledBlinkDuration = 15000; + +int currentLed = 0; +bool stopRequested = false; +unsigned long stopTime = 0; + +extern void setupLeds(); +extern void blinkLeds(); +extern bool shouldStopLeds(); + +extern void setupWiFi(); +extern void setupServer(); +extern void handleWebRequests(); +extern void checkRX(); + +extern void setupButton(); +extern void checkButton(); + +void setup() { + Serial.begin(115200); + setupWiFi(); + setupLeds(); + setupButton(); + setupServer(); +} + +void loop() { + handleWebRequests(); + checkRX(); + checkButton(); + + if (!shouldStopLeds()) { + blinkLeds(); + } +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_LED.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_LED.ino new file mode 100644 index 0000000..218483f --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_LED.ino @@ -0,0 +1,27 @@ +extern const int leds[]; +extern const int numLeds; +extern int currentLed; +extern bool stopRequested; +extern unsigned long stopTime; + +void setupLeds() { + for (int i = 0; i < numLeds; i++) { + pinMode(leds[i], OUTPUT); + digitalWrite(leds[i], LOW); + } +} + +void blinkLeds() { + digitalWrite(leds[currentLed], LOW); + currentLed = (currentLed + 1) % numLeds; + digitalWrite(leds[currentLed], HIGH); + delay(500); +} + +bool shouldStopLeds() { + if (stopRequested && millis() - stopTime < ledBlinkDuration) { + return true; + } + stopRequested = false; + return false; +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_Server.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_Server.ino new file mode 100644 index 0000000..5205913 --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_Server.ino @@ -0,0 +1,105 @@ +#include + +extern ESP8266WebServer server; +extern const char* ssid; +extern const char* password; + +extern bool stopRequested; +extern unsigned long stopTime; +extern const int CMD_STOP_L; +extern const int CMD_STOP_M; + +void handleRoot() { + String html = "\ + \ + \ + \ + \ + \ + \ +

ESP_L Controller

\ +
\ +
\ +
\ +
\ +
\ + \ + \ + \ + "; + server.send(200, "text/html", html); +} + +void handleSendCommand() { + if (server.hasArg("code")) { + int code = server.arg("code").toInt(); + Serial.println("Received command via web: " + String(code)); + + if (code == CMD_STOP_L) { + stopRequested = true; + stopTime = millis(); + server.send(200, "text/plain", "ESP_L stopped"); + } else if (code == CMD_STOP_M) { + Serial.write(CMD_STOP_M); + server.send(200, "text/plain", "Sent stop command to ESP_M"); + } + } else { + server.send(400, "text/plain", "Invalid command"); + } +} + +void checkRX() { + if (Serial.available() > 0) { + int received = Serial.read(); + Serial.println("Received via RX: " + String(received)); + + if (received == CMD_STOP_L || received == CMD_STOP_M) { + stopRequested = true; + stopTime = millis(); + } + } +} + +void setupWiFi() { + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + } +} + +void setupServer() { + server.on("/", handleRoot); + server.on("/send", handleSendCommand); + server.begin(); +} + +void handleWebRequests() { + server.handleClient(); +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_button.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_button.ino new file mode 100644 index 0000000..8d485d9 --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/M_ESP/M_button.ino @@ -0,0 +1,14 @@ +extern const int buttonPin; +extern bool stopRequested; +extern unsigned long stopTime; + +void setupButton() { + pinMode(buttonPin, INPUT); +} + +void checkButton() { + if (digitalRead(buttonPin) == HIGH) { + stopRequested = true; + stopTime = millis(); + } +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_ESP.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_ESP.ino new file mode 100644 index 0000000..2bfe2a4 --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_ESP.ino @@ -0,0 +1,49 @@ +#include +#include + +const int CMD_STOP_L = 65; +const int CMD_STOP_M = 66; + +const char* ssid = "iPhone de Vitaliy"; +const char* password = "iphone14"; + +ESP8266WebServer server(80); + +const int leds[] = {0, 13, 14}; +const int numLeds = sizeof(leds) / sizeof(leds[0]); +const int buttonPin = 12; +const int ledBlinkDuration = 15000; + +int currentLed = 0; +bool stopRequested = false; +unsigned long stopTime = 0; + +extern void setupLeds(); +extern void blinkLeds(); +extern bool shouldStopLeds(); + +extern void setupWiFi(); +extern void setupServer(); +extern void handleWebRequests(); +extern void checkRX(); + +extern void setupButton(); +extern void checkButton(); + +void setup() { + Serial.begin(115200); + setupWiFi(); + setupLeds(); + setupButton(); + setupServer(); +} + +void loop() { + handleWebRequests(); + checkRX(); + checkButton(); + + if (!shouldStopLeds()) { + blinkLeds(); + } +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_LED.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_LED.ino new file mode 100644 index 0000000..218483f --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_LED.ino @@ -0,0 +1,27 @@ +extern const int leds[]; +extern const int numLeds; +extern int currentLed; +extern bool stopRequested; +extern unsigned long stopTime; + +void setupLeds() { + for (int i = 0; i < numLeds; i++) { + pinMode(leds[i], OUTPUT); + digitalWrite(leds[i], LOW); + } +} + +void blinkLeds() { + digitalWrite(leds[currentLed], LOW); + currentLed = (currentLed + 1) % numLeds; + digitalWrite(leds[currentLed], HIGH); + delay(500); +} + +bool shouldStopLeds() { + if (stopRequested && millis() - stopTime < ledBlinkDuration) { + return true; + } + stopRequested = false; + return false; +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_Server.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_Server.ino new file mode 100644 index 0000000..c8e2ae5 --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_Server.ino @@ -0,0 +1,105 @@ +#include + +extern ESP8266WebServer server; +extern const char* ssid; +extern const char* password; + +extern bool stopRequested; +extern unsigned long stopTime; +extern const int CMD_STOP_L; +extern const int CMD_STOP_M; + +void handleRoot() { + String html = "\ + \ + \ + \ + \ + \ + \ +

ESP_M Controller

\ +
\ +
\ +
\ +
\ +
\ + \ + \ + \ + "; + server.send(200, "text/html", html); +} + +void handleSendCommand() { + if (server.hasArg("code")) { + int code = server.arg("code").toInt(); + Serial.println("Received command via web: " + String(code)); + + if (code == CMD_STOP_M) { + stopRequested = true; + stopTime = millis(); + server.send(200, "text/plain", "ESP_M stopped"); + } else if (code == CMD_STOP_L) { + Serial.write(CMD_STOP_L); + server.send(200, "text/plain", "Sent stop command to ESP_L"); + } + } else { + server.send(400, "text/plain", "Invalid command"); + } +} + +void checkRX() { + if (Serial.available() > 0) { + int received = Serial.read(); + Serial.println("Received via RX: " + String(received)); + + if (received == CMD_STOP_L || received == CMD_STOP_M) { + stopRequested = true; + stopTime = millis(); + } + } +} + +void setupWiFi() { + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + } +} + +void setupServer() { + server.on("/", handleRoot); + server.on("/send", handleSendCommand); + server.begin(); +} + +void handleWebRequests() { + server.handleClient(); +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_button.ino b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_button.ino new file mode 100644 index 0000000..f6202e3 --- /dev/null +++ b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/V_ESP/V_button.ino @@ -0,0 +1,14 @@ +extern const int buttonPin; +extern bool stopRequested; +extern unsigned long stopTime; + +void setupButton() { + pinMode(buttonPin, INPUT_PULLUP); +} + +void checkButton() { + if (digitalRead(buttonPin) == LOW) { + stopRequested = true; + stopTime = millis(); + } +} diff --git a/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/data/photo_2025-04-02_11-56-17.jpg b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/data/photo_2025-04-02_11-56-17.jpg new file mode 100644 index 0000000..c44cdc9 Binary files /dev/null and b/mc_labs/mc_lab_02/Staryk_Vitalii_Lab_02/data/photo_2025-04-02_11-56-17.jpg differ diff --git "a/mc_labs/mc_lab_02/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2262 (MK).pdf" "b/mc_labs/mc_lab_02/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2262 (MK).pdf" deleted file mode 100644 index ee147e9..0000000 Binary files "a/mc_labs/mc_lab_02/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2262 (MK).pdf" and /dev/null differ diff --git "a/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/data/\320\227\320\275\321\226\320\274\320\276\320\272 \320\265\320\272\321\200\320\260\320\275\320\260 2025-06-06 114055.png" "b/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/data/\320\227\320\275\321\226\320\274\320\276\320\272 \320\265\320\272\321\200\320\260\320\275\320\260 2025-06-06 114055.png" new file mode 100644 index 0000000..5b59bbb Binary files /dev/null and "b/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/data/\320\227\320\275\321\226\320\274\320\276\320\272 \320\265\320\272\321\200\320\260\320\275\320\260 2025-06-06 114055.png" differ diff --git a/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/main/main.ino b/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/main/main.ino new file mode 100644 index 0000000..bd915a2 --- /dev/null +++ b/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/main/main.ino @@ -0,0 +1,32 @@ +#include +#include +#include + +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 64 +#define OLED_RESET -1 + +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +void setup() { + Serial.begin(115200); + + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { + Serial.println("SSD1306 allocation failed"); + while (true); + } + + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(SSD1306_WHITE); + display.setCursor(0, 0); + display.println("Waiting for message..."); + display.display(); +} + +void loop() { + if (Serial.available() > 0) { + String message = Serial.readStringUntil('\n'); + showMessage(message); + } +} diff --git a/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/main/oled.ino b/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/main/oled.ino new file mode 100644 index 0000000..8b0c180 --- /dev/null +++ b/mc_labs/mc_lab_03/Staryk_Vitalii_Lab_03/main/oled.ino @@ -0,0 +1,10 @@ +#include + +void showMessage(String message) { + display.clearDisplay(); + display.setTextSize(1); + display.setCursor(0, 0); + display.println("Message:"); + display.println(message); + display.display(); +} diff --git "a/mc_labs/mc_lab_03/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2263 (MK).pdf" "b/mc_labs/mc_lab_03/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2263 (MK).pdf" deleted file mode 100644 index caf166a..0000000 Binary files "a/mc_labs/mc_lab_03/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2263 (MK).pdf" and /dev/null differ diff --git "a/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/data/\320\227\320\275\321\226\320\274\320\276\320\272 \320\265\320\272\321\200\320\260\320\275\320\260 2025-06-06 114055.png" "b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/data/\320\227\320\275\321\226\320\274\320\276\320\272 \320\265\320\272\321\200\320\260\320\275\320\260 2025-06-06 114055.png" new file mode 100644 index 0000000..5b59bbb Binary files /dev/null and "b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/data/\320\227\320\275\321\226\320\274\320\276\320\272 \320\265\320\272\321\200\320\260\320\275\320\260 2025-06-06 114055.png" differ diff --git a/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/connection.ino b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/connection.ino new file mode 100644 index 0000000..a9317f0 --- /dev/null +++ b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/connection.ino @@ -0,0 +1,63 @@ +const char* ssid = "iPhone de Vitaliy"; +const char* password = "iphone14"; +const char* mqtt_server = "9a5d1102c4ff49e28175850c39141c2c.s1.eu.hivemq.cloud"; +const int mqtt_port = 8883; +const char* mqtt_user = "ESP8266V"; +const char* mqtt_pass = "Esp8266V"; +const char* mqtt_topic = "emqx/esp8266"; + +WiFiClientSecure secureClient; +PubSubClient client(secureClient); + +void connectToWiFi() { + WiFi.begin(ssid, password); + Serial.print("Connecting to WiFi"); + while (WiFi.status() != WL_CONNECTED) { + Serial.print("."); + delay(500); + } + Serial.println("\nWiFi connected"); +} + +void setupTime() { + configTime(0, 0, "pool.ntp.org", "time.nist.gov"); + Serial.print("Waiting for time sync"); + while (time(nullptr) < 100000) { + Serial.print("."); + delay(500); + } + Serial.println("\nTime synchronized"); +} + +void mqttCallback(char* topic, byte* payload, unsigned int length) { + String message; + for (unsigned int i = 0; i < length; i++) { + message += (char)payload[i]; + } + Serial.print("Received: "); + Serial.println(message); + showMessage(message); +} + +void connectToMQTT() { + secureClient.setInsecure(); + + client.setServer(mqtt_server, mqtt_port); + client.setCallback(mqttCallback); + + while (!client.connected()) { + Serial.println("Connecting to MQTT..."); + if (client.connect("ESP8266Client", mqtt_user, mqtt_pass)) { + Serial.println("MQTT connected"); + client.subscribe(mqtt_topic); + client.publish(mqtt_topic, "ESP connected!"); + showConnectingAnimation(); + showWaiting(); + } else { + Serial.print("Failed, rc="); + Serial.print(client.state()); + Serial.println(" try again in 5 sec"); + delay(5000); + } + } +} diff --git a/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/main.ino b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/main.ino new file mode 100644 index 0000000..cb13b0b --- /dev/null +++ b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/main.ino @@ -0,0 +1,35 @@ +#include +#include +#include + +#include +#include +#include +#include + +void connectToWiFi(); +void setupTime(); +void connectToMQTT(); +void showWaiting(); + +void setup() { + Serial.begin(115200); + + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { + Serial.println("SSD1306 allocation failed"); + while (true); + } + display.clearDisplay(); + display.display(); + + connectToWiFi(); + setupTime(); + connectToMQTT(); +} + +void loop() { + if (!client.connected()) { + connectToMQTT(); + } + client.loop(); +} diff --git a/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/oled.ino b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/oled.ino new file mode 100644 index 0000000..aba29ea --- /dev/null +++ b/mc_labs/mc_lab_04/Staryk_Vitalii_Lab_04/main/oled.ino @@ -0,0 +1,45 @@ +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 64 +#define OLED_RESET -1 + +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +void showConnectingAnimation() { + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(SSD1306_WHITE); + display.setCursor(20, 20); + display.print("Connected"); + display.setCursor(20, 35); + for (int i = 0; i < 5; i++) { + display.print("."); + display.display(); + delay(1000); + } +} + +void showWaiting() { + display.clearDisplay(); + display.setCursor(0, 10); + display.setTextSize(1); + display.println("Waiting for message..."); + display.display(); +} + +void showMessage(String message) { + time_t now = time(nullptr); + struct tm* t = localtime(&now); + char timeStr[20]; + sprintf(timeStr, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec); + + display.clearDisplay(); + display.setTextSize(1); + display.setCursor(0, 0); + display.print("Message: "); + display.println(message); + display.setCursor(0, 20); + display.print("Received at:"); + display.setCursor(0, 30); + display.print(timeStr); + display.display(); +} diff --git a/mc_labs/mc_lab_04/lab4_example.ino b/mc_labs/mc_lab_04/lab4_example.ino deleted file mode 100644 index 7c1ab5d..0000000 --- a/mc_labs/mc_lab_04/lab4_example.ino +++ /dev/null @@ -1,154 +0,0 @@ - -#include -#define F_CPU 32000000UL // Clock frequency in Hz - -#define PRESCALER 256 // Timer prescaler value - -const int buzzerPin = 28; - -uint8_t number[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; - -uint8_t bcd_time[6] = { number[0], number[0], number[0], number[0], number[0], number[0] }; - -typedef struct Time { - uint8_t second = 0; - uint8_t minute = 0; - uint8_t hour = 0; -}Time_t; - -Time_t timerOne = { 0, 0, 0 }; -Time_t timerTwo = { 0, 0, 0 }; - -uint8_t key_cursor = 1; -uint8_t fig_number = 0; - -bool timer1_active = true; -bool timer1_started = false; -bool timer2_started = false; - -void bcd(uint8_t number, uint8_t position); -ISR(TIMER2_COMPA_vect) { - if (timer1_started) { - if (timerOne.second > 0 || timerOne.minute > 0 || timerOne.hour > 0) { - if (timerOne.second > 0) - timerOne.second--; - else { -timerOne.second = 59; - if (timerOne.minute > 0) { - timerOne.minute--; - } else { - timerOne.minute = 59; - if (timerOne.hour > 0) - timerOne.hour--; - } - } - } else { - for (int i = 0; i < 5; i++) { - digitalWrite(buzzerPin, HIGH); - delay(10000); - digitalWrite(buzzerPin, LOW); - delay(100); - } - timer1_started = false; - } - } - if (timer1_active) { - bcd(timerOne.hour, 0); - bcd(timerOne.minute, 2); - bcd(timerOne.second, 4); - } -} - - -ISR(TIMER0_COMPB_vect) { // Timer 0 interrupt - key_cursor <<= 1; - key_cursor &= 0b00111111; - if (key_cursor == 0) - key_cursor = 1; - - - fig_number++; - if (fig_number == 6) - fig_number = 0; - - - PORTC = key_cursor; - PORTB = ~bcd_time[fig_number]; -} - - -void setup() { - noInterrupts(); // Disable all interrupts - DDRC = 0xFF; // Port is output - PORTC = key_cursor; - DDRA = 0xFF; // Port is output - PORTA = 0x00; // +5V (segments off) - // Port B -- buttons - DDRD = 0x00; // Port is input - PORTD = 0xFF; - TCNT0 = 0; - OCR0A = 25; - TCCR0A = (1 << WGM01); // CTC - TCCR0B = (1 << CS02) | (1 << CS00); // Prescaler 1024 - TIMSK0 |= (1 << OCIE0A); // Output Compare Match A Interrupt Enable - - - TCCR2A = 0x00; - TCCR2B = (1 << WGM12) | (1 << CS12) | (1 << CS10); //CTC mode & Prescaler @ 1024 - TIMSK2 = (1 << OCIE2A); // дозвіл на переривання по співпадінню - OCR2A = 0x3D08 * 2;// compare value = 1 sec (16MHz AVR) - interrupts(); // Enable global interrupts - pinMode(buzzerPin, OUTPUT); - digitalWrite(buzzerPin, LOW); -} -void loop() { - // Button 1 - set hours - if ((PIND & (1 << 2)) == 0) { - if (timer1_active) { - if (++timerOne.hour == 24) - timerOne.hour = 0; - bcd(timerOne.hour, 0); - } else { - if (++timerTwo.hour == 24) - timerTwo.hour = 0; - bcd(timerTwo.hour, 0); - } - } - // Button 2 - set minutes - if ((PIND & (1 << 3)) == 0) { - if (timer1_active) { - if (++timerOne.minute == 60) - timerOne.minute = 0; - bcd(timerOne.minute, 2); - } else { - if (++timerTwo.minute == 60) - timerTwo.minute = 0; - bcd(timerTwo.minute, 2); - } - delay(100000); - } - // Button 3 - switch between timers - if ((PIND & (1 << 4)) == 0) { - timer1_active = !timer1_active; - } - // Button 4 - start/stop timer - if ((PIND & (1 << 5)) == 0) { - if (timer1_active && timer1_started) { - timerOne.hour = 0; - timerOne.minute = 0; - timerOne.second = 0; - bcd(timerOne.hour, 0); - bcd(timerOne.minute, 2); - bcd(timerOne.second, 4); - timer1_started = false; - } else if (timer1_active && !timer1_started) { - timer1_started = true; - } - } -} -void bcd(uint8_t fig_in, uint8_t position) { - uint8_t bcdL = fig_in % 10; - uint8_t bcdH = fig_in / 10; - bcd_time[position] = number[bcdH]; - bcd_time[position + 1] = number[bcdL]; -} diff --git a/mc_labs/mc_lab_04/mc_lab4_avr/Event.h b/mc_labs/mc_lab_04/mc_lab4_avr/Event.h deleted file mode 100644 index eac682b..0000000 --- a/mc_labs/mc_lab_04/mc_lab4_avr/Event.h +++ /dev/null @@ -1,63 +0,0 @@ - -#ifndef Event_h -#define Event_h - -#include -#include - -typedef void (*func_callback_t)(void*); - -enum EventType -{ - EVENT_NONE, - EVENT_EVERY, - EVENT_OSCILLATE -}; - -class Event -{ - -public: - Event(void) - { - eventType = EVENT_NONE; - } - - void update(uint32_t now=millis()) - { - if (now - lastEventTime >= period) - { - switch (eventType) - { - case EVENT_EVERY: - if (callback != NULL) - { - callback(void); - } - break; - - case EVENT_OSCILLATE: - pinState = ! pinState; - digitalWrite(pin, pinState); - break; - } - lastEventTime = now; - count++; - } - if (repeatCount > -1 && count >= repeatCount) - { - eventType = EVENT_NONE; - } - } - - int8_t eventType = EVENT_NONE; - uint32_t period; - int16_t repeatCount = -1; - uint8_t pin; - uint8_t pinState; - func_callback_t callback = NULL; - uint32_t lastEventTime; - int16_t count; -}; - -#endif \ No newline at end of file diff --git a/mc_labs/mc_lab_04/mc_lab4_avr/Timer.cpp b/mc_labs/mc_lab_04/mc_lab4_avr/Timer.cpp deleted file mode 100644 index 2081182..0000000 --- a/mc_labs/mc_lab_04/mc_lab4_avr/Timer.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#if defined(ARDUINO) && ARDUINO >= 100 -#include "Arduino.h" -#else -#include "WProgram.h" -#endif - -#include "Timer.h" - -Timer::Timer(void) -{ -} - -int8_t Timer::every(unsigned long period, void (*callback)(), int repeatCount) -{ - int8_t i = findFreeEventIndex(); - if (i == -1) return -1; - - _events[i].eventType = EVENT_EVERY; - _events[i].period = period; - _events[i].repeatCount = repeatCount; - _events[i].callback = callback; - _events[i].lastEventTime = millis(); - _events[i].count = 0; - return i; -} - -int8_t Timer::every(unsigned long period, void (*callback)()) -{ - return every(period, callback, -1); // - means forever -} - -int8_t Timer::after(unsigned long period, void (*callback)()) -{ - return every(period, callback, 1); -} - -int8_t Timer::oscillate(uint8_t pin, unsigned long period, uint8_t startingValue, int repeatCount) -{ - int8_t i = findFreeEventIndex(); - if (i == NO_TIMER_AVAILABLE) return NO_TIMER_AVAILABLE; - - _events[i].eventType = EVENT_OSCILLATE; - _events[i].pin = pin; - _events[i].period = period; - _events[i].pinState = startingValue; - digitalWrite(pin, startingValue); - _events[i].repeatCount = repeatCount * 2; // full cycles not transitions - _events[i].lastEventTime = millis(); - _events[i].count = 0; - return i; -} - -int8_t Timer::oscillate(uint8_t pin, unsigned long period, uint8_t startingValue) -{ - return oscillate(pin, period, startingValue, -1); // forever -} - -/** - * This method will generate a pulse of !startingValue, occuring period after the - * call of this method and lasting for period. The Pin will be left in !startingValue. - */ -int8_t Timer::pulse(uint8_t pin, unsigned long period, uint8_t startingValue) -{ - return oscillate(pin, period, startingValue, 1); // once -} - -/** - * This method will generate a pulse of startingValue, starting immediately and of - * length period. The pin will be left in the !startingValue state - */ -int8_t Timer::pulseImmediate(uint8_t pin, unsigned long period, uint8_t pulseValue) -{ - int8_t id(oscillate(pin, period, pulseValue, 1)); - // now fix the repeat count - if (id >= 0 && id < MAX_NUMBER_OF_EVENTS) { - _events[id].repeatCount = 1; - } - return id; -} - - -void Timer::stop(int8_t id) -{ - if (id >= 0 && id < MAX_NUMBER_OF_EVENTS) { - _events[id].eventType = EVENT_NONE; - } -} - -void Timer::update(void) -{ - unsigned long now = millis(); - update(now); -} - -void Timer::update(unsigned long now) -{ - for (int8_t i = 0; i < MAX_NUMBER_OF_EVENTS; i++) - { - if (_events[i].eventType != EVENT_NONE) - { - _events[i].update(now); - } - } -} -int8_t Timer::findFreeEventIndex(void) -{ - for (int8_t i = 0; i < MAX_NUMBER_OF_EVENTS; i++) - { - if (_events[i].eventType == EVENT_NONE) - { - return i; - } - } - return NO_TIMER_AVAILABLE; -} \ No newline at end of file diff --git a/mc_labs/mc_lab_04/mc_lab4_avr/Timer.h b/mc_labs/mc_lab_04/mc_lab4_avr/Timer.h deleted file mode 100644 index 55854fc..0000000 --- a/mc_labs/mc_lab_04/mc_lab4_avr/Timer.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef Timer_h -#define Timer_h - -#include "Event.h" - -#define MAX_NUMBER_OF_EVENTS (10) - -#define TIMER_NOT_AN_EVENT (-2) -#define NO_TIMER_AVAILABLE (-1) - -class Timer -{ - -public: - Timer(void) - { - } - - int8_t every(uint32_t period, func_callback_t callback, int16_t repeatCount = -1) - { - int8_t i = findFreeEventIndex(); - if (i == -1) - return -1; - - _events[i].eventType = EVENT_EVERY; - _events[i].period = period; - _events[i].repeatCount = repeatCount; - if (callback != NULL) - { - _events[i].callback = callback; - } - _events[i].lastEventTime = millis(); - _events[i].count = 0; - return i; - } - - int8_t after(uint32_t duration, func_callback_t callback) - { - return every(duration, callback, 1); - } - - int8_t oscillate(uint8_t pin, uint32_t period, uint8_t startingValue, int16_t repeatCount = -1) - { - int8_t i = findFreeEventIndex(); - if (i == NO_TIMER_AVAILABLE) - return NO_TIMER_AVAILABLE; - - _events[i].eventType = EVENT_OSCILLATE; - _events[i].pin = pin; - _events[i].period = period; - _events[i].pinState = startingValue; - digitalWrite(pin, startingValue); - _events[i].repeatCount = repeatCount * 2; // full cycles not transitions - _events[i].lastEventTime = millis(); - _events[i].count = 0; - return i; - } - - /** - * This method will generate a pulse of !startingValue, occuring period after the - * call of this method and lasting for period. The Pin will be left in !startingValue. - */ - int8_t pulse(uint8_t pin, uint32_t period, uint8_t startingValue) - { - return oscillate(pin, period, startingValue, 1); // once - } - - /** - * This method will generate a pulse of pulseValue, starting immediately and of - * length period. The pin will be left in the !pulseValue state - */ - int8_t pulseImmediate(uint8_t pin, uint32_t period, uint8_t pulseValue) - { - int8_t id(oscillate(pin, period, pulseValue, 1)); - // now fix the repeat count - if (id >= 0 && id < MAX_NUMBER_OF_EVENTS) - { - _events[id].repeatCount = 1; - } - return id; - } - - void stop(int8_t id) - { - if (id >= 0 && id < MAX_NUMBER_OF_EVENTS) - { - _events[id].eventType = EVENT_NONE; - } - } - - // void update(void) - // { - // update(millis()); - // } - - void update(uint32_t now=millis()) - { - for (int8_t i = 0; i < MAX_NUMBER_OF_EVENTS; i++) - { - if (_events[i].eventType != EVENT_NONE) - { - _events[i].update(now); - } - } - } - -protected: - Event _events[MAX_NUMBER_OF_EVENTS]; - int8_t findFreeEventIndex(void) - { - for (int8_t i = 0; i < MAX_NUMBER_OF_EVENTS; i++) - { - if (_events[i].eventType == EVENT_NONE) - { - return i; - } - } - return NO_TIMER_AVAILABLE; - } -}; - -#endif \ No newline at end of file diff --git a/mc_labs/mc_lab_04/mc_lab4_avr/mc_lab4_avr.ino b/mc_labs/mc_lab_04/mc_lab4_avr/mc_lab4_avr.ino deleted file mode 100644 index bfa4d38..0000000 --- a/mc_labs/mc_lab_04/mc_lab4_avr/mc_lab4_avr.ino +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * - Code by Simon Monk - http://www.simonmonk.org -* * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef Timer_h -#define Timer_h - -#include -#include "Event.h" - -#define MAX_NUMBER_OF_EVENTS (10) - -#define TIMER_NOT_AN_EVENT (-2) -#define NO_TIMER_AVAILABLE (-1) - -class Timer -{ - -public: - Timer(void); - - int8_t every(unsigned long period, void (*callback)(void)); - int8_t every(unsigned long period, void (*callback)(void), int repeatCount); - int8_t after(unsigned long duration, void (*callback)(void)); - int8_t oscillate(uint8_t pin, unsigned long period, uint8_t startingValue); - int8_t oscillate(uint8_t pin, unsigned long period, uint8_t startingValue, int repeatCount); - - /** - * This method will generate a pulse of !startingValue, occuring period after the - * call of this method and lasting for period. The Pin will be left in !startingValue. - */ - int8_t pulse(uint8_t pin, unsigned long period, uint8_t startingValue); - - /** - * This method will generate a pulse of pulseValue, starting immediately and of - * length period. The pin will be left in the !pulseValue state - */ - int8_t pulseImmediate(uint8_t pin, unsigned long period, uint8_t pulseValue); - void stop(int8_t id); - void update(void); - void update(unsigned long now); - -protected: - Event _events[MAX_NUMBER_OF_EVENTS]; - int8_t findFreeEventIndex(void); - -}; - -#endif \ No newline at end of file diff --git "a/mc_labs/mc_lab_04/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2264 (\320\234\320\232).pdf" "b/mc_labs/mc_lab_04/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2264 (\320\234\320\232).pdf" deleted file mode 100644 index 02c03c7..0000000 Binary files "a/mc_labs/mc_lab_04/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\2264 (\320\234\320\232).pdf" and /dev/null differ diff --git "a/mc_labs/mc_lab_05/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22605 (MK).pdf" "b/mc_labs/mc_lab_05/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22605 (MK).pdf" deleted file mode 100644 index f347907..0000000 Binary files "a/mc_labs/mc_lab_05/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22605 (MK).pdf" and /dev/null differ diff --git "a/mc_labs/mc_lab_06/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22606 (MK).pdf" "b/mc_labs/mc_lab_06/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22606 (MK).pdf" deleted file mode 100644 index e0124f7..0000000 Binary files "a/mc_labs/mc_lab_06/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22606 (MK).pdf" and /dev/null differ diff --git "a/mc_labs/mc_lab_07/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22607 (MK).pdf" "b/mc_labs/mc_lab_07/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22607 (MK).pdf" deleted file mode 100644 index d227533..0000000 Binary files "a/mc_labs/mc_lab_07/\320\227\320\260\320\262\320\264\320\260\320\275\320\275\321\217 \342\204\22607 (MK).pdf" and /dev/null differ diff --git a/utils/AVR_CALCULATOR/avrcalc.exe b/utils/AVR_CALCULATOR/avrcalc.exe deleted file mode 100644 index 6f8bb12..0000000 Binary files a/utils/AVR_CALCULATOR/avrcalc.exe and /dev/null differ diff --git a/utils/LCDAsisst/LCDAssistant.exe b/utils/LCDAsisst/LCDAssistant.exe deleted file mode 100644 index 428e034..0000000 Binary files a/utils/LCDAsisst/LCDAssistant.exe and /dev/null differ diff --git a/utils/LCDAsisst/cmd/LCDAssistant.ini b/utils/LCDAsisst/cmd/LCDAssistant.ini deleted file mode 100644 index f9e0cd5..0000000 --- a/utils/LCDAsisst/cmd/LCDAssistant.ini +++ /dev/null @@ -1,6 +0,0 @@ -[General] -PixelsPerByte=4 -Vertical=0 -IncludeSize=1 -LittleEndian=1 -BigEndian=0 \ No newline at end of file diff --git a/utils/LCDAsisst/cmd/LCDAssistantCMD.exe b/utils/LCDAsisst/cmd/LCDAssistantCMD.exe deleted file mode 100644 index f84c225..0000000 Binary files a/utils/LCDAsisst/cmd/LCDAssistantCMD.exe and /dev/null differ diff --git a/utils/arduino-cli.exe b/utils/arduino-cli.exe deleted file mode 100644 index a4a024c..0000000 Binary files a/utils/arduino-cli.exe and /dev/null differ