diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/oled/oled.cpp | 10 | ||||
| -rw-r--r-- | lib/oled/oled.h | 16 | ||||
| -rw-r--r-- | lib/rgb/rgb.cpp | 75 | ||||
| -rw-r--r-- | lib/rgb/rgb.h | 11 |
4 files changed, 70 insertions, 42 deletions
diff --git a/lib/oled/oled.cpp b/lib/oled/oled.cpp index 0c433f2..0634527 100644 --- a/lib/oled/oled.cpp +++ b/lib/oled/oled.cpp @@ -5,16 +5,16 @@ // #include "settings.h" // #include "oled.h" -// Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &Wire, -1); -// void oled_init() { +// 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(); // } -// void oled_print(const String& text, int x, int y) { +// void OLED::print(const String& text, int x, int y) { // display.setTextSize(1); // display.setTextColor(WHITE); // display.setCursor(x, y); @@ -22,12 +22,12 @@ // display.display(); // } -// void oled_clear() { +// void OLED::clear() { // display.clearDisplay(); // display.display(); // } -// void oled_drawBox() { +// 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 e229dbe..426842a 100644 --- a/lib/oled/oled.h +++ b/lib/oled/oled.h @@ -2,8 +2,14 @@ // #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(); +// class OLED +// { +// public: +// OLED(); +// void clear(); +// void print(const String &text, int x, int y); +// void drawBox(); +// void setCursor(int x, int y); +// void setTextSize(int size); +// void showAnimation(); +// };
\ No newline at end of file diff --git a/lib/rgb/rgb.cpp b/lib/rgb/rgb.cpp index a748006..469cf3d 100644 --- a/lib/rgb/rgb.cpp +++ b/lib/rgb/rgb.cpp @@ -7,7 +7,6 @@ int RGB::scaleColor(uint8_t val) return map(val, 0, 255, 0, 1023); } - RGB::RGB() { pinMode(RED_PIN, OUTPUT); @@ -15,53 +14,72 @@ RGB::RGB() pinMode(BLUE_PIN, OUTPUT); } - -void RGB::setColorRGB(uint8_t red, uint8_t green, uint8_t blue) +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)); + if (saveColor) + { + currentR = red; + currentG = green; + currentB = 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--) + int startR = currentR; + int startG = currentG; + int startB = currentB; + + for (int i = 0; i <= duration; i++) { - setColorRGB(red * i / 255, green * i / 255, blue * i / 255); - delay(duration / 255); - } -} + uint8_t newR = startR + ((red - startR) * i) / duration; + uint8_t newG = startG + ((green - startG) * i) / duration; + uint8_t newB = startB + ((blue - startB) * i) / duration; + setColorRGB(newR, newG, newB, false); + delay(1); + } -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) +void RGB::blink(int cycles, int interval) { - for (int i = 0; i <= 255; i++) + for (int i = 0; i < cycles; i++) { - setColorRGB(red * i / 255, green * i / 255, blue * i / 255); - delay(duration / 255); + setColorRGB(0, 0, 0, false); + delay(interval); + setColorRGB(currentR, currentG, currentB, false); + delay(interval); } - for (int i = 255; i >= 0; i--) +} + +void RGB::breathe(int cycles, int interval) +{ + uint8_t baseR = currentR; + uint8_t baseG = currentG; + uint8_t baseB = currentB; + + for (int c = 0; c < cycles; ++c) { - setColorRGB(red * i / 255, green * i / 255, blue * i / 255); - delay(duration / 255); + for (int i = 0; i <= 255; ++i) + { + setColorRGB(baseR * i / 255, baseG * i / 255, baseB * i / 255, false); + delay(interval / 510); + } + + for (int i = 255; i >= 0; --i) + { + setColorRGB(baseR * i / 255, baseG * i / 255, baseB * i / 255, false); + delay(interval / 510); + } } -} + setColorRGB(baseR, baseG, baseB); +} void RGB::rainbowCycle(int duration) { @@ -73,4 +91,5 @@ void RGB::rainbowCycle(int duration) setColorRGB(red, green, blue); delay(duration / 256); } + setColorRGB(currentR, currentG, currentB, false); } diff --git a/lib/rgb/rgb.h b/lib/rgb/rgb.h index 562e9dd..2f50088 100644 --- a/lib/rgb/rgb.h +++ b/lib/rgb/rgb.h @@ -6,14 +6,17 @@ class RGB { public: + uint8_t currentR; + uint8_t currentG; + uint8_t currentB; + RGB(); - void setColorRGB(uint8_t red, uint8_t green, uint8_t blue); + 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 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 blink(int cycles, int interval); + void breathe(int duration, int interval); void rainbowCycle(int duration); private: int scaleColor(uint8_t val); }; - |