-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRainbowLED.ino
49 lines (32 loc) · 1012 Bytes
/
RainbowLED.ino
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
struct Color_t {
float r,g,b;
static Color_t Red() {
return Color_t { 255.f, 0.f, 0.f };
}
static Color_t Green() {
return Color_t { 0.f, 255.f, 0.f };
}
static Color_t Blue() {
return Color_t { 0.f, 0.f, 255.f };
}
};
void ModulateColor(Color_t From, Color_t To, int Time) {
float r = (To.r - From.r ) / Time;
float g = (To.g - From.g ) / Time;
float b = (To.b - From.b ) / Time;
for (int i = 0; i <= Time; i++) {
auto OutR = (int)map((From.r + r * i), 0.f, 255.f, 255.f, 0.f);
auto OutG = (int)map((From.g + g * i), 0.f, 255.f, 255.f, 0.f);
auto OutB = (int)map((From.b + b * i), 0.f, 255.f, 255.f, 0.f);
analogWrite(9, OutR);
analogWrite(10, OutG);
analogWrite(11, OutB);
delay(5);
}
}
void setup() { }
void loop() {
ModulateColor(Color_t::Red(), Color_t::Green(),500.f);
ModulateColor(Color_t::Green(), Color_t::Blue(), 500.f);
ModulateColor(Color_t::Blue(), Color_t::Red(), 500.f);
}