-
Notifications
You must be signed in to change notification settings - Fork 1
/
led.h
32 lines (26 loc) · 827 Bytes
/
led.h
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
#define PIN_RED 4 // GIOP23
#define PIN_GREEN 16 // GIOP22
#define PIN_BLUE 17 // GIOP21
#define RPWMRES 8
#define GPWMRES 8
#define BPWMRES 8
int br = 0;
void ledSetup() {
ledcSetup(0, 12000, RPWMRES);
ledcSetup(1, 12000, GPWMRES);
ledcSetup(2, 12000, BPWMRES);
ledcAttachPin(4, 0);
ledcAttachPin(16, 1);
ledcAttachPin(17, 2);
}
void setLedBrightness(int brightness) {
br = map(brightness, 0, 4095, 255, 0);
}
void setColor(uint8_t r, uint8_t g, uint8_t b) {
ledcWrite(0, map(map(r, 255, 0, 100, 0), 0, 255, 255, br));
ledcWrite(1, map(g, 0, 255, 255, br));
ledcWrite(2, map(map(b, 255, 0, 150, 0), 0, 255, 255, br));
// ledcWrite(0, map(map(r, 255, 0, 100, 0), 0, 255, 255, br));
// ledcWrite(1, map(g, 0, 255, 255, br));
// ledcWrite(2, map(map(b, 255, 0, 150, 0), 0, 255, 255, br));
}