summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json3
-rw-r--r--Bez tytułu.pngbin1212584 -> 0 bytes
-rw-r--r--include/README4
-rw-r--r--include/settings.h20
-rw-r--r--lib/README16
-rw-r--r--lib/oled/oled.cpp46
-rw-r--r--lib/oled/oled.h5
-rw-r--r--lib/rgb/rgb.cpp74
-rw-r--r--lib/rgb/rgb.h4
-rw-r--r--platformio.ini6
-rw-r--r--src/main.cpp40
11 files changed, 130 insertions, 88 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
deleted file mode 100644
index 70e34ec..0000000
--- a/.vscode/settings.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "C_Cpp.errorSquiggles": "disabled"
-} \ No newline at end of file
diff --git a/Bez tytułu.png b/Bez tytułu.png
deleted file mode 100644
index f539fc4..0000000
--- a/Bez tytułu.png
+++ /dev/null
Binary files differ
diff --git a/include/README b/include/README
index 194dcd4..49819c0 100644
--- a/include/README
+++ b/include/README
@@ -25,9 +25,7 @@ new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
-In C, the usual convention is to give header files names that end with `.h'.
-It is most portable to use only letters, digits, dashes, and underscores in
-header file names, and at most one dot.
+In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
diff --git a/include/settings.h b/include/settings.h
index 45fd574..4fb4a48 100644
--- a/include/settings.h
+++ b/include/settings.h
@@ -5,20 +5,20 @@ 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;
+const int SCL_PIN = 8;
+const int SDA_PIN = 10;
// RGB LED
-const int RED_PIN = D6;
-const int GREEN_PIN = D5;
-const int BLUE_PIN = D0;
+const int RED_PIN = 2;
+const int GREEN_PIN = 4;
+const int BLUE_PIN = 6;
// MOTORS
-const int IN1 = D7;
-const int IN2 = D8;
+// const int IN1 = D7;
+// const int IN2 = D8;
-const int IN3 = D3;
-const int IN4 = D4;
+// const int IN3 = D3;
+// const int IN4 = D4;
// BUZZER
-const int BUZZER_PIN = A0; \ No newline at end of file
+// const int BUZZER_PIN = 3; \ No newline at end of file
diff --git a/lib/README b/lib/README
index 2593a33..9379397 100644
--- a/lib/README
+++ b/lib/README
@@ -1,11 +1,11 @@
This directory is intended for project specific (private) libraries.
-PlatformIO will compile them to static libraries and link into executable file.
+PlatformIO will compile them to static libraries and link into the executable file.
-The source code of each library should be placed in an own separate directory
-("lib/your_library_name/[here are source files]").
+The source code of each library should be placed in a separate directory
+("lib/your_library_name/[Code]").
-For example, see a structure of the following two libraries `Foo` and `Bar`:
+For example, see the structure of the following example libraries `Foo` and `Bar`:
|--lib
| |
@@ -15,7 +15,7 @@ For example, see a structure of the following two libraries `Foo` and `Bar`:
| | |--src
| | |- Bar.c
| | |- Bar.h
-| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
+| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
@@ -27,7 +27,7 @@ For example, see a structure of the following two libraries `Foo` and `Bar`:
|--src
|- main.c
-and a contents of `src/main.c`:
+Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>
@@ -39,8 +39,8 @@ int main (void)
```
-PlatformIO Library Dependency Finder will find automatically dependent
-libraries scanning project source files.
+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
diff --git a/lib/oled/oled.cpp b/lib/oled/oled.cpp
index 0634527..db1b556 100644
--- a/lib/oled/oled.cpp
+++ b/lib/oled/oled.cpp
@@ -6,28 +6,38 @@
// #include "oled.h"
-// OLED::OLED() {
-// Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &Wire, -1);
-// Wire.begin(SDA_PIN, SCL_PIN);
-// display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
-// display.clearDisplay();
-// display.display();
+// OLED::OLED() : display(OLED_WIDTH, OLED_HEIGHT, &Wire, -1)
+// {
+// // Najpierw uruchom I2C
+// Wire.begin(SDA_PIN, SCL_PIN);
+
+// // Potem dopiero inicjalizuj OLED
+// if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
+// Serial.println("OLED init failed!");
+// }
+
+// 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::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::clear()
+// {
+// display.clearDisplay();
+// display.display();
// }
-// void OLED::drawBox() {
-// display.drawRect(0, 0, 128, 64, WHITE);
-// 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
index 426842a..7cda336 100644
--- a/lib/oled/oled.h
+++ b/lib/oled/oled.h
@@ -12,4 +12,7 @@
// void setCursor(int x, int y);
// void setTextSize(int size);
// void showAnimation();
-// }; \ No newline at end of file
+
+// private:
+// Adafruit_SSD1306 display;
+// };
diff --git a/lib/rgb/rgb.cpp b/lib/rgb/rgb.cpp
index 469cf3d..174a9e5 100644
--- a/lib/rgb/rgb.cpp
+++ b/lib/rgb/rgb.cpp
@@ -1,24 +1,41 @@
#include <Arduino.h>
#include "settings.h"
#include "rgb.h"
+#include <math.h>
+
+
+// Kanały PWM (muszą być unikalne)
+#define RED_CHANNEL 0
+#define GREEN_CHANNEL 1
+#define BLUE_CHANNEL 2
+
+// Częstotliwość PWM i rozdzielczość
+#define PWM_FREQ 5000
+#define PWM_RES 10 // 10-bit (0–1023)
int RGB::scaleColor(uint8_t val)
{
- return map(val, 0, 255, 0, 1023);
+ return map(val, 0, 255, 0, (1 << PWM_RES) - 1);
}
RGB::RGB()
{
- pinMode(RED_PIN, OUTPUT);
- pinMode(GREEN_PIN, OUTPUT);
- pinMode(BLUE_PIN, OUTPUT);
+ ledcSetup(RED_CHANNEL, PWM_FREQ, PWM_RES);
+ ledcAttachPin(RED_PIN, RED_CHANNEL);
+
+ ledcSetup(GREEN_CHANNEL, PWM_FREQ, PWM_RES);
+ ledcAttachPin(GREEN_PIN, GREEN_CHANNEL);
+
+ ledcSetup(BLUE_CHANNEL, PWM_FREQ, PWM_RES);
+ ledcAttachPin(BLUE_PIN, BLUE_CHANNEL);
}
void RGB::setColorRGB(uint8_t red, uint8_t green, uint8_t blue, bool saveColor = true)
{
- analogWrite(RED_PIN, scaleColor(red));
- analogWrite(GREEN_PIN, scaleColor(green));
- analogWrite(BLUE_PIN, scaleColor(blue));
+ ledcWrite(RED_CHANNEL, scaleColor(red));
+ ledcWrite(GREEN_CHANNEL, scaleColor(green));
+ ledcWrite(BLUE_CHANNEL, scaleColor(blue));
+
if (saveColor)
{
currentR = red;
@@ -27,6 +44,7 @@ void RGB::setColorRGB(uint8_t red, uint8_t green, uint8_t blue, bool saveColor =
}
}
+
void RGB::fadeColor(uint8_t red, uint8_t green, uint8_t blue, int duration)
{
int startR = currentR;
@@ -57,39 +75,53 @@ void RGB::blink(int cycles, int interval)
}
}
-void RGB::breathe(int cycles, int interval)
+void RGB::breathe(int cycles, int period)
{
+ const int steps = 128;
+ int stepDelay = period / (steps * 2);
+
uint8_t baseR = currentR;
uint8_t baseG = currentG;
uint8_t baseB = currentB;
for (int c = 0; c < cycles; ++c)
{
- for (int i = 0; i <= 255; ++i)
+ for (int i = 0; i <= steps; ++i)
{
- setColorRGB(baseR * i / 255, baseG * i / 255, baseB * i / 255, false);
- delay(interval / 510);
+ float scale = (float)i / steps;
+ setColorRGB(baseR * scale, baseG * scale, baseB * scale, false);
+ delay(stepDelay);
}
- for (int i = 255; i >= 0; --i)
+
+ for (int i = steps; i >= 0; --i)
{
- setColorRGB(baseR * i / 255, baseG * i / 255, baseB * i / 255, false);
- delay(interval / 510);
+ float scale = (float)i / steps;
+ setColorRGB(baseR * scale, baseG * scale, baseB * scale, false);
+ delay(stepDelay);
}
}
setColorRGB(baseR, baseG, baseB);
}
-void RGB::rainbowCycle(int duration)
+
+void RGB::rainbowCycle(int duration, float speed)
{
- for (int i = 0; i < 256; i++)
+ // speed (0.1 – slow, 1.0 – normal, 2.0 – fast)
+ const int steps = 256;
+
+ for (int i = 0; i < steps; 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);
+ float angle = i * speed * 0.024;
+ int red = sin(angle) * 127 + 128;
+ int green = sin(angle + 2) * 127 + 128;
+ int blue = sin(angle + 4) * 127 + 128;
+
+ setColorRGB(red, green, blue, false);
+ delay(duration / steps);
}
+
setColorRGB(currentR, currentG, currentB, false);
}
+
diff --git a/lib/rgb/rgb.h b/lib/rgb/rgb.h
index 2f50088..3850f0a 100644
--- a/lib/rgb/rgb.h
+++ b/lib/rgb/rgb.h
@@ -14,8 +14,8 @@ public:
void setColorRGB(uint8_t red, uint8_t green, uint8_t blue, bool saveColor);
void fadeColor(uint8_t red, uint8_t green, uint8_t blue, int duration);
void blink(int cycles, int interval);
- void breathe(int duration, int interval);
- void rainbowCycle(int duration);
+ void breathe(int cycles, int period);
+ void rainbowCycle(int duration, float speed);
private:
int scaleColor(uint8_t val);
diff --git a/platformio.ini b/platformio.ini
index 31cbf82..5034d06 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -8,9 +8,9 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
-[env:d1_mini]
-platform = espressif8266
-board = d1_mini
+[env:adafruit_feather_esp32s2]
+platform = espressif32
+board = adafruit_feather_esp32s2
framework = arduino
lib_deps =
adafruit/Adafruit GFX Library@^1.12.0
diff --git a/src/main.cpp b/src/main.cpp
index 34d760c..c48769c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,27 +1,29 @@
#include <Arduino.h>
-// #include "oled.h"
+#include "settings.h"
#include "rgb.h"
+#include "oled.h"
-
-// OLED oled;
RGB rgb;
-void setup() {
-
- // oled_init();
- //oled_print("siema", 0, 10);
- // oled_drawBox();
-
-
- // pinMode(IN1, OUTPUT);
- // pinMode(IN2, OUTPUT);
-
- // pinMode(IN3, OUTPUT);
- // pinMode(IN4, OUTPUT);
-}
-
-void loop() {
-
+void setup()
+{
}
+void loop()
+{
+ // rgb.setColorRGB(255, 0, 0, true);
+ // delay(1000);
+ // rgb.fadeColor(0, 255, 0, 1000);
+ // delay(1000);
+ // rgb.blink(3, 500);
+ // delay(1000);
+ // rgb.breathe(4, 1000);
+ // rgb.rainbowCycle(8000, 1.0);
+ // rgb.setColorRGB(0, 0, 0, true);
+ // delay(1000);
+ // rgb.rainbowCycle(8000, 1);
+ // rgb.setColorRGB(0, 0, 0, true);
+ // delay(1000);
+ // rgb.rainbowCycle(8000, 2);
+} \ No newline at end of file