summaryrefslogtreecommitdiff
path: root/lib/rgb
diff options
context:
space:
mode:
authorEnricoGuccii <partyka.003@gmail.com>2025-05-11 13:55:44 +0200
committerEnricoGuccii <partyka.003@gmail.com>2025-05-11 13:55:44 +0200
commitcf9a1f07ed519cadd58e38794616d0a9596be4ae (patch)
tree11f7c879517e5e861e0914ddee317ec04ce8690b /lib/rgb
parent7da514aa6ec19df49828fd87013ba284f338fbdd (diff)
add buzzer
Diffstat (limited to 'lib/rgb')
-rw-r--r--lib/rgb/rgb.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/lib/rgb/rgb.cpp b/lib/rgb/rgb.cpp
index 174a9e5..249e7f0 100644
--- a/lib/rgb/rgb.cpp
+++ b/lib/rgb/rgb.cpp
@@ -3,15 +3,12 @@
#include "rgb.h"
#include <math.h>
+#define RED_CHANNEL 0
+#define GREEN_CHANNEL 1
+#define BLUE_CHANNEL 2
-// 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)
+#define PWM_FREQ 5000
+#define PWM_RES 10
int RGB::scaleColor(uint8_t val)
{
@@ -44,7 +41,6 @@ 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;
@@ -77,8 +73,8 @@ void RGB::blink(int cycles, int interval)
void RGB::breathe(int cycles, int period)
{
- const int steps = 128;
- int stepDelay = period / (steps * 2);
+ const int steps = 128;
+ int stepDelay = period / (steps * 2);
uint8_t baseR = currentR;
uint8_t baseG = currentG;
@@ -93,7 +89,6 @@ void RGB::breathe(int cycles, int period)
delay(stepDelay);
}
-
for (int i = steps; i >= 0; --i)
{
float scale = (float)i / steps;
@@ -105,7 +100,6 @@ void RGB::breathe(int cycles, int period)
setColorRGB(baseR, baseG, baseB);
}
-
void RGB::rainbowCycle(int duration, float speed)
{
// speed (0.1 – slow, 1.0 – normal, 2.0 – fast)
@@ -114,9 +108,9 @@ void RGB::rainbowCycle(int duration, float speed)
for (int i = 0; i < steps; i++)
{
float angle = i * speed * 0.024;
- int red = sin(angle) * 127 + 128;
+ int red = sin(angle) * 127 + 128;
int green = sin(angle + 2) * 127 + 128;
- int blue = sin(angle + 4) * 127 + 128;
+ int blue = sin(angle + 4) * 127 + 128;
setColorRGB(red, green, blue, false);
delay(duration / steps);
@@ -124,4 +118,3 @@ void RGB::rainbowCycle(int duration, float speed)
setColorRGB(currentR, currentG, currentB, false);
}
-