-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstripcontrol.cpp
114 lines (110 loc) · 2.69 KB
/
stripcontrol.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
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
#include "stripcontrol.h"
void setupStrips(int striplen)
{
// reset control pins.
// sometimes they are on a special function.
pinMode(WS2812_PIN, INPUT);
if(striplen <= 1 || striplen >= 1000)
{
striplen = 1;
}
if(stripselect == ANALOGSTRIP)
{
setupAnalogStrip();
}
if(stripselect == WS2812)
{
// amount, pin
setupWS2812(striplen, WS2812_PIN);
}
if(stripselect == WS2801)
{
// freq, amount
setupWS2801(1e6, striplen);
}
delay(100);
}
void handleStrips()
{
// check which effect is select.
// and do pattern dependend on ledstrip.
double brightfact = (stripcontrol.brightness+1)/100.0;
int r = ((double)stripcontrol.varZero)*brightfact;
int g = ((double)stripcontrol.varOne)*brightfact;
int b = ((double)stripcontrol.varTwo)*brightfact;
int speed = stripcontrol.varZero+1;
if(stripcontrol.effect == RGBCOLORS)
{
if(stripselect == ANALOGSTRIP)
{
writeRgb(r, g, b);
}
else if(stripselect == WS2801)
{
setWS2801Strip(r, g, b);
updateWS2801();
}
else if(stripselect == WS2812)
{
setWS2812Strip(r, g, b);
updateWS2812();
}
}
else if(stripcontrol.effect == FADING)
{
int brightness = stripcontrol.brightness+1;
if(stripselect == ANALOGSTRIP)
{
fadeRgb(speed, brightness);
delay(1);
}
else if(stripselect == WS2801)
{
fadeWS2801(speed, brightness);
updateWS2801();
}
else if(stripselect == WS2812)
{
fadeWS2812(speed, brightness);
updateWS2812();
delay(1);
}
}
// rainbow effect
else if(stripcontrol.effect == DIGITALFADING)
{
int brightness = stripcontrol.brightness+1;
if(stripselect == WS2812)
{
rainbowWS2812(speed, brightness);
updateWS2812();
}
else if(stripselect == WS2801)
{
rainbowWS2801(speed, brightness);
updateWS2801();
}
}
}
void debugPrintStripControl()
{
char fmtstr[100];
sprintf(fmtstr,
"\nDebug:\n"
"pincode: %d\n"
"effect: %d\n"
"brightness: %d\n"
"var0: %d\n"
"var1: %d\n"
"var2: %d\n"
"changed: %d\n",
stripcontrol.pincode,
stripcontrol.effect,
stripcontrol.brightness,
stripcontrol.varZero,
stripcontrol.varOne,
stripcontrol.varTwo,
stripcontrol.changed
);
Serial.println(fmtstr);
}