-
Notifications
You must be signed in to change notification settings - Fork 0
/
LedUtils.cpp
45 lines (40 loc) · 1.24 KB
/
LedUtils.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
42
43
44
45
#include "LedUtils.h"
struct Life *L=(Life *)malloc(sizeof(struct Life)*LIVES);
float ramp[]={
0, 0.01, 0.02, 0.04, 0.08, 0.16, 0.32, .36, .4, .45, .5, .55, .6, .65, .7, .75, .8, .85, .9, .95,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
.95, .9, .85, .8, .75, .7, .65, .6, .55, .5, .45, .4, .36, .32, .16, 0.08, 0.04, 0.02, 0.01, 0
};
// ----- RGB LED code -----
// int rs = sizeof(ramp)/sizeof(ramp[0]); // ramp size
void lightRGB(uint8_t r, uint8_t g, uint8_t b){
if (RGB_PIN < 0){
log_v("Skipped lightRGB because RGB_PIN<0");
return;
}
rgbLedWriteOrdered(RGB_PIN, LED_COLOR_ORDER_RGB, r, g, b);
}
void breath(struct Life lf, int bs)
{
int s = bs;
lightRGB(uint8_t(lf.r*ramp[s]), uint8_t(lf.g*ramp[s]), uint8_t(lf.b*ramp[s]) );
}
// void ledBreath(int r=-1,int g=-1, int b=-1, int rgb_delay=50) {
void ledBreath(int r,int g, int b, int rgb_delay) {
if (RGB_PIN < 0){
log_v("Skipped ledBreath because RGB_PIN<0");
return;
}
int l=0;
if(r<0) r=rand()%RGB_BRIGHTNESS;
if(g<0) g=rand()%RGB_BRIGHTNESS;
if(b<0) b=rand()%RGB_BRIGHTNESS;
L[l].r=r;
L[l].g=g;
L[l].b=b;
int ramp_n = sizeof(ramp)/sizeof(ramp[0]);
for(int b=0; b<ramp_n; b++){
breath(L[l], b);
vTaskDelay(rgb_delay/portTICK_PERIOD_MS);
}
}