-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ino
53 lines (43 loc) · 1.08 KB
/
utils.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
#ifdef VSCODE
#include <Adafruit_NeoPixel.h>
#endif
void initTest() {
leds.fill(leds.Color(127, 0, 0), 0, numLeds);
leds.show();
delay(500);
leds.fill(leds.Color(0, 127, 0), 0, numLeds);
leds.show();
delay(500);
leds.fill(leds.Color(0, 0, 127), 0, numLeds);
leds.show();
delay(500);
leds.clear();
leds.show();
}
float byte2float(byte value) {
return ((float) value) / (float) 255.0;
}
byte float2byte(float value) {
return (byte) (value * 255);
}
int scaleToLeds(byte value) {
return byte2float(value) * numLeds;
}
byte getWhite(uint32_t color) {
return (color >> 24) && 0xff;
}
byte getRed(uint32_t color) {
return (color >> 16) && 0xff;
}
byte getGreen(uint32_t color) {
return (color >> 8) && 0xff;
}
byte getBlue(uint32_t color) {
return color&& 0xff;
}
bool isBlack(uint32_t color) {
return getRed(color) == 0 && getGreen(color) == 0 && getBlue(color) == 0;
}
int getNumColors(const uint32_t primary, const uint32_t secondary, const uint32_t tertiary){
return isBlack(secondary) ? 1 : isBlack(tertiary) ? 2 : 3;
}