forked from Beanow/Arduino-Shift-Light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorPicker.cpp
41 lines (36 loc) · 882 Bytes
/
ColorPicker.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
#include "ColorPicker.h"
#define HUE_STEP 16
#define WHITE_I 16
#define BLACK_I 17
static CHSV makeHSV(uint8_t index){
if(index == WHITE_I)
return CHSV(0, 0, 255);
if(index == BLACK_I)
return CHSV(0, 0, 0);
return CHSV(index*HUE_STEP, 255, 255);
}
CRGB ColorPicker::at(uint8_t index, bool allowBlack){
CRGB color;
hsv2rgb_rainbow(makeHSV(index), color);
return color;
}
CRGB ColorPicker::next(uint8_t &index, bool allowBlack){
index++;
if(allowBlack && index > BLACK_I)
index = 0;
if(!allowBlack && index > WHITE_I)
index = 0;
return at(index, allowBlack);
}
CRGB ColorPicker::prev(uint8_t &index, bool allowBlack){
if(index == 0){
if(allowBlack)
index = BLACK_I;
else
index = WHITE_I;
}
else{
index--;
}
return at(index, allowBlack);
}