-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrixLicht.cpp
263 lines (209 loc) · 5.99 KB
/
MatrixLicht.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include "MatrixLicht.h"
// pins for Matrix
#define CLK 11
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
// Matrix panel
RGBmatrixPanel rgb_matrix(A, B, C, D, CLK, LAT, OE, false);
MatrixLicht::MatrixLicht(RGB_LED rotary_encoder_led) {
rainbow_einstell_modus = 0; // 0:Grundeinstellungen 1:Farbe 2:Helligkeit 3:Farbe an Matrix
rainbow_rgb_phase = 1; // rainbow RGB phasen 1:RG 2:GB 3:BR 4:White
rotary_led = rotary_encoder_led;
//value RGB Aus:0 An:255
valueRed = 0;
valueGreen = 0;
valueBlue = 0;
hell = 50; //Helligkeit 100:hell 0:aus
rotary_led.doFineSerialOutput(false);
animation_count = 0;
}
void MatrixLicht::setup() {
rgb_matrix.begin();
rgb_matrix.fillScreen(rgb_matrix.Color888(0, 0, 0));
rotary_led.rgb_ausgabe(0, 0, 0);
}
void MatrixLicht::loop() {
// nothing to be done on a regular basis
}
void MatrixLicht::setWithRotaryEncoder(ClickEncoder *encoder, int s, ClickEncoder::Button b) {
// long click: operation abbrechen
if (rainbow_einstell_modus >0 && b == ClickEncoder::Held) {
rainbow_einstell_modus = 0;
Serial.println("MatrixLicht setting cancelled.");
printToSerialModus();
}
else if (rainbow_einstell_modus == 0) {
Grundeinstellung();
if (b == ClickEncoder::Clicked) {
rainbow_einstell_modus = 1;
printToSerialModus();
}
}
else if (rainbow_einstell_modus == 1) {
rainbow(s);
if (b == ClickEncoder::Clicked) {
rainbow_einstell_modus = 2;
printToSerialModus();
}
}
else if (rainbow_einstell_modus == 2) {
brightness(s);
if (b == ClickEncoder::Clicked) {
rainbow_einstell_modus = 3;
printToSerialModus();
}
}
else if (rainbow_einstell_modus == 3) {
sendSelectedColorToMatrix();
rainbow_einstell_modus = 0;
printToSerialModus();
}
} /* loop*/
void MatrixLicht::startSetting() {
rainbow_einstell_modus = 1;
printToSerialModus();
}
bool MatrixLicht::isSettingFinished() {
return rainbow_einstell_modus == 0;
}
void MatrixLicht::Grundeinstellung() {
rotary_led.black();
}
void MatrixLicht::sendSelectedColorToMatrix() {
double faktor = hell / 100.0;
int red2 = faktor * valueRed;
int green2 = faktor * valueGreen;
int blue2 = faktor * valueBlue;
Serial.print("Farbe an Matrix :^) ");
Serial.print(red2);
Serial.print(" ");
Serial.print(green2);
Serial.print(" ");
Serial.println(blue2);
black();
//rgb_matrix.fillScreen(rgb_matrix.Color888(0, 0, 0));
delay(500);
for (int i = 1; i < 25; i++) {
rgb_matrix.fillCircle(15, 15, i, rgb_matrix.Color888(red2, green2, blue2, true));
delay(20);
}
rotary_led.black();
}
/**
Einstellen der Helligkeit
*/
void MatrixLicht::brightness(int s) {
hell = hell + s;
if (hell < 0) {
hell = 0;
}
if (hell > 100) {
hell = 100;
}
rotary_led.rgb_ausgabe(valueRed, valueGreen, valueBlue, hell);
}
/**
Rainbow macht ein Farbübergang abhängig vom Parameter "schritt"
*/
void MatrixLicht::rainbow(int schritt ) {
// wenn Matrix aus war -> rot
if (valueRed <10 && valueGreen <10 && valueBlue <10){
valueRed = 255;
}
if ( rainbow_rgb_phase == 1) {
valueRed = valueRed - schritt;
valueGreen = 255 - valueRed;
if (valueGreen > 255) {
rainbow_rgb_phase = 2;
valueRed = 0;
valueGreen = 255;
}
else if (valueRed > 255) {
rainbow_rgb_phase = 1; //unnötig
valueRed = 255;
valueGreen = 0;
}
else {
rotary_led.rgb_ausgabe(valueRed, valueGreen, valueBlue);
}
}
if ( rainbow_rgb_phase == 2) {
valueGreen = valueGreen - schritt;
valueBlue = 255 - valueGreen;
if (valueBlue > 255) {
rainbow_rgb_phase = 3;
valueGreen = 0;
valueBlue = 255;
}
else if (valueGreen > 255) {
rainbow_rgb_phase = 1;
valueBlue = 0;
valueGreen = 255;
}
else {
rotary_led.rgb_ausgabe(valueRed, valueGreen, valueBlue);
}
}
if ( rainbow_rgb_phase == 3) {
valueBlue = valueBlue - schritt;
valueRed = 255 - valueBlue;
if (valueRed > 255) {
rainbow_rgb_phase = 4;
valueBlue = 0;
valueRed = 255;
}
else if (valueBlue > 255) {
rainbow_rgb_phase = 2;
valueRed = 0;
valueBlue = 255;
}
else {
rotary_led.rgb_ausgabe(valueRed, valueGreen, valueBlue);
}
}
if (rainbow_rgb_phase == 4) {
valueRed = 255;
valueGreen = 255;
valueBlue = 255;
//nur eine schnelle Bewegung
if (schritt < -2) {
rainbow_rgb_phase = 3;
valueRed = 250;
valueGreen = 0;
valueBlue = 5;
}
else {
rotary_led.rgb_ausgabe(valueRed, valueGreen, valueBlue);
}
}
}
void MatrixLicht::printToSerialModus() {
Serial.print("rainbow_einstell_modus: ");
Serial.println(rainbow_einstell_modus);
}
void MatrixLicht::black() {
//rgb_matrix.fillScreen(rgb_matrix.Color888(0, 0, 0));
for (int i = 1; i < 25; i++) {
rgb_matrix.fillCircle(15, 15, i, rgb_matrix.Color888(0, 0, 0, true));
delay(5);
}
}
void MatrixLicht::alarmAnimation() {
animation_count ++;
if (animation_count > 25) {
animation_count = 0;
}
rgb_matrix.drawCircle(15, 15, (animation_count ) % 25, rgb_matrix.Color888(0, 0, 0, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 1) % 25, rgb_matrix.Color888(255, 0, 0, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 2) % 25, rgb_matrix.Color888(0, 255, 0, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 3) % 25, rgb_matrix.Color888(0, 0, 255, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 4) % 25, rgb_matrix.Color888(127, 127, 0, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 5) % 25, rgb_matrix.Color888(0, 127, 127, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 6) % 25, rgb_matrix.Color888(127, 0, 127, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 7) % 25, rgb_matrix.Color888(85, 85, 85, true));
rgb_matrix.drawCircle(15, 15, (animation_count + 8) % 25, rgb_matrix.Color888(0, 0, 0, true));
}