summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnricoGuccii <partyka.003@gmail.com>2025-05-07 13:02:37 +0200
committerEnricoGuccii <partyka.003@gmail.com>2025-05-07 13:02:37 +0200
commitfe73dbbf9b6864c2064ec8d002a8a1212fafb54a (patch)
tree8401ac231d01dc3788008adb988b09c7bf1e8b0e
parentd7ea4d727b14870829464f79839acd60b82faa0b (diff)
file structure, rgb class
-rw-r--r--Bez tytułu.pngbin0 -> 1212584 bytes
-rw-r--r--include/settings.h24
-rw-r--r--lib/oled/oled.cpp33
-rw-r--r--lib/oled/oled.h9
-rw-r--r--lib/rgb/rgb.cpp76
-rw-r--r--lib/rgb/rgb.h19
-rw-r--r--platformio.ini5
-rw-r--r--src/main.cpp81
8 files changed, 239 insertions, 8 deletions
diff --git a/Bez tytułu.png b/Bez tytułu.png
new file mode 100644
index 0000000..f539fc4
--- /dev/null
+++ b/Bez tytułu.png
Binary files differ
diff --git a/include/settings.h b/include/settings.h
new file mode 100644
index 0000000..45fd574
--- /dev/null
+++ b/include/settings.h
@@ -0,0 +1,24 @@
+#pragma once
+
+// OLED
+const int OLED_WIDTH = 128;
+const int OLED_HEIGHT = 64;
+const int OLED_ADDR = 0x3C;
+
+const int SDA_PIN = D2;
+const int SCL_PIN = D1;
+
+// RGB LED
+const int RED_PIN = D6;
+const int GREEN_PIN = D5;
+const int BLUE_PIN = D0;
+
+// MOTORS
+const int IN1 = D7;
+const int IN2 = D8;
+
+const int IN3 = D3;
+const int IN4 = D4;
+
+// BUZZER
+const int BUZZER_PIN = A0; \ No newline at end of file
diff --git a/lib/oled/oled.cpp b/lib/oled/oled.cpp
new file mode 100644
index 0000000..0c433f2
--- /dev/null
+++ b/lib/oled/oled.cpp
@@ -0,0 +1,33 @@
+// #include <Arduino.h>
+// #include <Wire.h>
+// #include <Adafruit_GFX.h>
+// #include <Adafruit_SSD1306.h>
+// #include "settings.h"
+// #include "oled.h"
+
+// Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &Wire, -1);
+
+// void oled_init() {
+// Wire.begin(SDA_PIN, SCL_PIN);
+// display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
+// display.clearDisplay();
+// display.display();
+// }
+
+// void oled_print(const String& text, int x, int y) {
+// display.setTextSize(1);
+// display.setTextColor(WHITE);
+// display.setCursor(x, y);
+// display.println(text);
+// display.display();
+// }
+
+// void oled_clear() {
+// display.clearDisplay();
+// display.display();
+// }
+
+// void oled_drawBox() {
+// display.drawRect(0, 0, 128, 64, WHITE);
+// display.display();
+// }
diff --git a/lib/oled/oled.h b/lib/oled/oled.h
new file mode 100644
index 0000000..e229dbe
--- /dev/null
+++ b/lib/oled/oled.h
@@ -0,0 +1,9 @@
+// #pragma once
+// #include <Adafruit_SSD1306.h>
+// #include "settings.h"
+
+
+// void oled_init();
+// void oled_clear();
+// void oled_print(const String& text, int x, int y);
+// void oled_drawBox();
diff --git a/lib/rgb/rgb.cpp b/lib/rgb/rgb.cpp
new file mode 100644
index 0000000..a748006
--- /dev/null
+++ b/lib/rgb/rgb.cpp
@@ -0,0 +1,76 @@
+#include <Arduino.h>
+#include "settings.h"
+#include "rgb.h"
+
+int RGB::scaleColor(uint8_t val)
+{
+ return map(val, 0, 255, 0, 1023);
+}
+
+
+RGB::RGB()
+{
+ pinMode(RED_PIN, OUTPUT);
+ pinMode(GREEN_PIN, OUTPUT);
+ pinMode(BLUE_PIN, OUTPUT);
+}
+
+
+void RGB::setColorRGB(uint8_t red, uint8_t green, uint8_t blue)
+{
+ analogWrite(RED_PIN, scaleColor(red));
+ analogWrite(GREEN_PIN, scaleColor(green));
+ analogWrite(BLUE_PIN, scaleColor(blue));
+}
+
+
+void RGB::fadeColor(uint8_t red, uint8_t green, uint8_t blue, int duration)
+{
+ for (int i = 0; i <= 255; i++)
+ {
+ setColorRGB(red * i / 255, green * i / 255, blue * i / 255);
+ delay(duration / 255);
+ }
+ for (int i = 255; i >= 0; i--)
+ {
+ setColorRGB(red * i / 255, green * i / 255, blue * i / 255);
+ delay(duration / 255);
+ }
+}
+
+
+void RGB::blinkColor(uint8_t red, uint8_t green, uint8_t blue, int duration)
+{
+ setColorRGB(red, green, blue);
+ delay(duration);
+ setColorRGB(0, 0, 0);
+ delay(duration);
+}
+
+
+void RGB::breatheColor(uint8_t red, uint8_t green, uint8_t blue, int duration)
+{
+ for (int i = 0; i <= 255; i++)
+ {
+ setColorRGB(red * i / 255, green * i / 255, blue * i / 255);
+ delay(duration / 255);
+ }
+ for (int i = 255; i >= 0; i--)
+ {
+ setColorRGB(red * i / 255, green * i / 255, blue * i / 255);
+ delay(duration / 255);
+ }
+}
+
+
+void RGB::rainbowCycle(int duration)
+{
+ for (int i = 0; i < 256; i++)
+ {
+ int red = sin(i * 0.024) * 127 + 128;
+ int green = sin(i * 0.024 + 2) * 127 + 128;
+ int blue = sin(i * 0.024 + 4) * 127 + 128;
+ setColorRGB(red, green, blue);
+ delay(duration / 256);
+ }
+}
diff --git a/lib/rgb/rgb.h b/lib/rgb/rgb.h
new file mode 100644
index 0000000..562e9dd
--- /dev/null
+++ b/lib/rgb/rgb.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "settings.h"
+#include <Arduino.h>
+
+class RGB
+{
+public:
+ RGB();
+ void setColorRGB(uint8_t red, uint8_t green, uint8_t blue);
+ void fadeColor(uint8_t red, uint8_t green, uint8_t blue, int duration);
+ void blinkColor(uint8_t red, uint8_t green, uint8_t blue, int duration);
+ void breatheColor(uint8_t red, uint8_t green, uint8_t blue, int duration);
+ void rainbowCycle(int duration);
+
+private:
+ int scaleColor(uint8_t val);
+};
+
diff --git a/platformio.ini b/platformio.ini
index 4fa4a6d..31cbf82 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -12,3 +12,8 @@
platform = espressif8266
board = d1_mini
framework = arduino
+lib_deps =
+ adafruit/Adafruit GFX Library@^1.12.0
+ adafruit/Adafruit SSD1306@^2.5.13
+
+build_flags = -Iinclude \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 13e25b3..453eb0b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,16 +1,81 @@
#include <Arduino.h>
+#include "oled.h"
+#include "rgb.h"
+void setup() {
+ // oled_init();
+ //oled_print("siema", 0, 10);
+ // oled_drawBox();
+
+
+ // pinMode(RED_PIN, OUTPUT);
+ // pinMode(GREEN_PIN, OUTPUT);
+ // pinMode(BLUE_PIN, OUTPUT);
-#define LED_PIN 2
+ // pinMode(IN1, OUTPUT);
+ // pinMode(IN2, OUTPUT);
-void setup() {
-
- pinMode(LED_PIN, OUTPUT);
- digitalWrite(LED_PIN, LOW);
+ // pinMode(IN3, OUTPUT);
+ // pinMode(IN4, OUTPUT);
}
void loop() {
-
-
-
+
+ // setColorRGB(255, 0, 0); // Red
+ // oled_print(" red", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // setColorRGB(0, 255, 0); // Green
+ // oled_print(" green", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // setColorRGB(0, 0, 255); // Blue
+ // oled_print(" blue", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // setColorRGB(255, 255, 0); // Yellow
+ // oled_print(" yellow", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // setColorRGB(0, 255, 255); // Cyan
+ // oled_print(" cyan", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // setColorRGB(255, 0, 255); // Magenta
+ // oled_print(" magenta", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // setColorRGB(255, 255, 255); // White
+ // oled_print(" white", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // setColorRGB(0, 0, 0); // Off
+ // oled_print(" off", 0, 10);
+ // delay(2500);
+ // oled_clear();
+ // digitalWrite(RED_PIN, HIGH);
+ // digitalWrite(GREEN_PIN, LOW);
+ // digitalWrite(BLUE_PIN, LOW);
+ // digitalWrite(IN1, HIGH);
+ // digitalWrite(IN2, LOW);
+ // digitalWrite(IN3, HIGH);
+ // digitalWrite(IN4, LOW);
+ // delay(2000);
+ // digitalWrite(RED_PIN, LOW);
+ // digitalWrite(GREEN_PIN, HIGH);
+ // digitalWrite(BLUE_PIN, LOW);
+ // digitalWrite(IN1, LOW);
+ // digitalWrite(IN2, HIGH);
+ // digitalWrite(IN3, LOW);
+ // digitalWrite(IN4, HIGH);
+ // delay(2000);
+ // digitalWrite(RED_PIN, LOW);
+ // digitalWrite(GREEN_PIN, LOW);
+ // digitalWrite(BLUE_PIN, HIGH);
+ // digitalWrite(IN1, LOW);
+ // digitalWrite(IN2, HIGH);
+ // digitalWrite(IN3, HIGH);
+ // digitalWrite(IN4, LOW);
+ // delay(2000);
}
+