-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathled.ino
116 lines (99 loc) · 2.44 KB
/
led.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
String myh;
String myb;
String mys;
float h;
float b;
float s;
uint32_t currbri;
uint32_t r;
uint32_t g;
uint32_t bl;
void setPixelColor( uint16_t n, uint16_t brightness) {
pixels.setPixelColor(n, (brightness * r / 255) , (brightness * g / 255), (brightness * bl / 255));
}
uint32_t HSVColor(float h, float s, float v) {
h = constrain(h, 0, 360);
s = constrain(s, 0, 1);
v = constrain(v, 0, 1);
int i, b, p, q, t;
float f;
h /= 60.0; // sector 0 to 5
i = floor( h );
f = h - i; // factorial part of h
b = v * 255;
p = v * ( 1 - s ) * 255;
q = v * ( 1 - s * f ) * 255;
t = v * ( 1 - s * ( 1 - f ) ) * 255;
switch ( i ) {
case 0:
r = b; g = t; bl = p;
return pixels.Color(b, t, p);
case 1:
r = q; g = b; bl = p;
return pixels.Color(q, b, p);
case 2:
r = p; g = b; bl = t;
return pixels.Color(p, b, t);
case 3:
r = p; g = q; bl = b;
return pixels.Color(p, q, b);
case 4:
r = t; g = p; bl = b;
return pixels.Color(t, p, b);
default:
r = b; g = p; bl = q;
return pixels.Color(b, p, q);
}
}
void CallBrightness(uint32_t i) {
HSVColor(h, s, b);
for (int j = 0; j < NUMPIXELS; j++) {
setPixelColor(j, i * 2.5);
}
pixels.show();
/*
pixels.setBrightness(i);
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(150, 0, 0)); // Moderately bright green color.
}
pixels.show(); // This sends the updated pixel color to the hardware.
*/
}
void hueSet() {
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, HSVColor(h, s, b));
}
pixels.show();
}
void extractLEDDetails(String payload) {
//payload[length] = '\0';
//String input = (char*)payload;
String input = payload;
Serial.println(input);
if (input.indexOf("LIGHTON") > -1) {
b = currbri;
}
if (input.indexOf("LIGHTOFF") > -1) {
currbri = b;
b = 0;
}
int count = input.length();
if (input.indexOf("brightness") > -1) {
myb = input.substring(10, count);
b = myb.toInt();
}
if (input.indexOf("hue") > -1) {
myh = input.substring(3, count);
h = myh.toInt();
}
if (input.indexOf("saturation") > -1) {
mys = input.substring(10, count);
s = mys.toInt();
}
//hueSet();
Serial.println("Hue: " + myh);
Serial.println("Brightness: " + myb);
Serial.println("Sat: " + mys);
CallBrightness(b);
}