-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgb.cpp
67 lines (61 loc) · 1.59 KB
/
rgb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "rgb.h"
void setRGB(int redValue, int greenValue, int blueValue) {
analogWrite(RGB_LED_RED, 255 - redValue);
analogWrite(RGB_LED_GREEN, 255 - greenValue);
analogWrite(RGB_LED_BLUE, 255 - blueValue);
}
void turnOffRGB() { setRGB(0, 0, 0); }
void fadeInRGB(int red, int green, int blue, int redEnd, int greenEnd,
int blueEnd, int loopDelay) {
bool complete = false;
bool redRev = redEnd < red;
bool greenRev = greenEnd < green;
bool blueRev = blueEnd < blue;
while (!complete) {
complete = true;
if (red != redEnd) {
redRev ? red-- : red++;
complete = false;
}
if (green != greenEnd) {
greenRev ? green-- : green++;
complete = false;
}
if (blue != blueEnd) {
blueRev ? blue-- : blue++;
complete = false;
}
setRGB(red, green, blue);
delay(loopDelay);
}
}
void blueFlick(bool reverse = false) {
if (!reverse) {
fadeInRGB(0, 0, 0, 0, 0, 255, 10);
setRGB(0, 255, 255);
delay(30);
turnOffRGB();
} else {
setRGB(0, 255, 255);
delay(30);
fadeInRGB(0, 0, 255, 0, 0, 0, 10);
}
}
void blinkRGBCode(String str) {
blueFlick();
delay(300);
for (int i = 0; i < str.length(); i++) {
char digit = str.charAt(i);
int blinkCount = digit - '0'; // Convert the character to an integer
long red = i % 2 == 0 ? 0 : 255;
long green = i % 2 == 0 ? 255 : 0;
long blue = 0;
delay(1500);
for (int j = 0; j < blinkCount; j++) {
// fadeInRGB(0, 0, 0, red, green, blue, 1);
fadeInRGB(red, green, blue, 0, 0, 0, 2);
}
}
delay(300);
blueFlick(true);
}