-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightManager.cpp
More file actions
93 lines (77 loc) · 1.71 KB
/
LightManager.cpp
File metadata and controls
93 lines (77 loc) · 1.71 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "LightManager.h"
#include <stdint.h>
#include <functional>
LightManager::LightManager()
: pixels(1, 5, NEO_GRB + NEO_KHZ800) {}
void LightManager::setColorWithAnimation(Color color)
{
bool isAnimating = currentColor != color;
while (isAnimating)
{
if (currentColor.r < color.r)
{
currentColor.r += 1;
}
else if (currentColor.r > color.r)
{
currentColor.r -= 1;
}
if (currentColor.g < color.g)
{
currentColor.g += 1;
}
else if (currentColor.g > color.g)
{
currentColor.g -= 1;
}
if (currentColor.b < color.b)
{
currentColor.b += 1;
}
else if (currentColor.b > color.b)
{
currentColor.b -= 1;
}
pixels.setPixelColor(0, pixels.Color(currentColor.r, currentColor.g, currentColor.b));
pixels.show();
delay(1);
isAnimating = currentColor != color;
};
}
void LightManager::blink()
{
pixels.setPixelColor(0, pixels.Color(cyan.r, cyan.g, cyan.b));
pixels.show();
delay(100);
pixels.setPixelColor(0, pixels.Color(black.r, black.g, black.b));
pixels.show();
delay(1500);
}
void LightManager::turnOnCyan()
{
setColorWithAnimation(cyan);
}
void LightManager::turnOnGreen()
{
setColorWithAnimation(green);
}
void LightManager::turnOnMagenta()
{
setColorWithAnimation(magenta);
}
void LightManager::turnOnRed()
{
setColorWithAnimation(red);
}
void LightManager::turnOnBlack()
{
setColorWithAnimation(black);
}
void LightManager::turnOnOrange()
{
setColorWithAnimation(orange);
}
void LightManager::setup()
{
pixels.begin();
}