@@ -55,7 +55,7 @@ static String getDateTimeStringByParams(tm *newtime, char* pattern = (char *)"%d
55
55
return buffer;
56
56
}
57
57
58
- static uint8_t splitColor ( uint32_t c, char value )
58
+ static uint8_t splitRGBColor ( uint32_t c, char value )
59
59
{
60
60
switch ( value ) {
61
61
case ' r' : return (uint8_t )(c >> 16 );
@@ -65,12 +65,23 @@ static uint8_t splitColor ( uint32_t c, char value )
65
65
}
66
66
}
67
67
68
+ static uint32_t saturateColor (uint32_t c, float saturation)
69
+ {
70
+ uint8_t w = floor ((uint8_t )(c >> 24 ));
71
+ uint8_t r = floor ((uint8_t )(c >> 16 ));
72
+ uint8_t g = floor ((uint8_t )(c >> 8 ));
73
+ uint8_t b = floor ((uint8_t )c);
74
+
75
+ uint32_t newColor = strip.Color (r + (255 - r) * saturation,g + (255 - g) * saturation, b + (255 - b) * saturation, 0 );
76
+
77
+ return newColor;
78
+ }
79
+
68
80
/* *
69
81
* Input time in epoch format format and return String with format pattern
70
82
* by Renzo Mischianti <www.mischianti.org>
71
83
*/
72
84
static String getEpochStringByParams (long time, char * pattern = (char *)"%d/%m/%Y %I:%M:%S"){
73
- // struct tm *newtime;
74
85
tm newtime;
75
86
newtime = getDateTimeByParams (time);
76
87
return getDateTimeStringByParams (&newtime, pattern);
@@ -87,6 +98,19 @@ static boolean isBetween(int value, int min, int max) {
87
98
return false ;
88
99
}
89
100
101
+ /* *
102
+ * Check if a certain value is in the given list
103
+ */
104
+ static boolean isIn (uint8_t value, uint8_t list[]) {
105
+ for (int i = 0 ; i < (sizeof (list) / sizeof (list[0 ])); i++) {
106
+ if (list[i] == value) {
107
+ return true ;
108
+ }
109
+ }
110
+
111
+ return false ;
112
+ }
113
+
90
114
/* *
91
115
* Get led number by X and Y coordinates. 0/0 is bottom left.
92
116
*/
@@ -103,8 +127,8 @@ struct time {
103
127
uint8_t minute;
104
128
};
105
129
106
- int lastUpdate;
107
- uint32_t color = strip.Color(0 ,0 ,0 ,255 );
130
+ int lastUpdate = 0 ;
131
+ uint32_t color = strip.Color(0 ,255 ,0 ,0 );
108
132
109
133
uint8_t currentLeds[114 ];
110
134
uint8_t nextLeds[114 ];
@@ -127,7 +151,7 @@ void setup() {
127
151
}
128
152
129
153
void onConnectionEstablished () {
130
- String currentValue = String (splitColor (color, ' r' )) + " ," + String (splitColor (color, ' g' )) + " ," + String (splitColor (color, ' b' ));
154
+ String currentValue = String (splitRGBColor (color, ' r' )) + " ," + String (splitRGBColor (color, ' g' )) + " ," + String (splitRGBColor (color, ' b' ));
131
155
client.publish (STAT, " color" , currentValue);
132
156
133
157
client.subscribe (" color" , [] (const String &payload) {
@@ -179,19 +203,12 @@ void loop() {
179
203
setNextLeds (t.hour , t.minute );
180
204
181
205
if (currentTimeStamp % 5 == 0 || lastUpdate == 0 ) {
206
+ Serial.println (" Start transition" );
182
207
transition ();
208
+ } else {
209
+ showNextLeds ();
183
210
}
184
-
185
- strip.clear ();
186
- for (int i = 0 ; i < (sizeof (nextLeds) / sizeof (nextLeds[0 ])); i++) {
187
- if (nextLeds[i] == 1 ) {
188
- strip.setPixelColor (i, color);
189
- }
190
-
191
- currentLeds[i] = nextLeds[i];
192
- }
193
- strip.show ();
194
-
211
+
195
212
lastUpdate = currentTimeStamp;
196
213
}
197
214
@@ -478,19 +495,21 @@ void transition() {
478
495
479
496
// Add all current active leds to the additionalLeds, they should be active till they are "hit" by the line in the same column
480
497
for (int i = 0 ; i < (sizeof (currentLeds) / sizeof (currentLeds[0 ])); i++) {
481
- additionalLeds[i] = currentLeds[i];
498
+ if (isBetween (i, 0 , 109 )) {
499
+ additionalLeds[i] = currentLeds[i];
500
+ }
482
501
}
483
502
484
503
// Start the main transition cycles
485
- for (int i = 0 ; i < iterations; i++) {
486
- // Clear the intermediat led array
504
+ for (int i = 0 ; i <= iterations; i++) {
505
+ // Clear the intermediate led array
487
506
memset (interLeds, 0 , sizeof (interLeds));
488
507
489
508
for (int col = 0 ; col < 11 ; col++) {
490
509
for (int row = 0 ; row < lengths[col]; row++) {
491
510
int led = getLedXY (col, startPositions[col] - i + row);
492
511
493
- if (isBetween (led, 0 , 110 )) {
512
+ if (isBetween (led, 0 , 109 )) {
494
513
interLeds[led] = 1 ;
495
514
}
496
515
}
@@ -502,7 +521,13 @@ void transition() {
502
521
if (interLeds[i] == 1 ) {
503
522
additionalLeds[i] = 0 ;
504
523
505
- strip.setPixelColor (i, color);
524
+ float saturation = random (0 , 100 ) / 100.0 ;
525
+ uint32_t newColor = color;
526
+ if (saturation < 0.5 && i <= 109 && nextLeds[i] != 1 ) {
527
+ newColor = saturateColor (color, saturation);
528
+ }
529
+
530
+ strip.setPixelColor (i, newColor);
506
531
}
507
532
508
533
if (nextLeds[i] == 1 ) {
@@ -512,13 +537,19 @@ void transition() {
512
537
513
538
for (int i = 0 ; i < (sizeof (additionalLeds) / sizeof (additionalLeds[0 ])); i++) {
514
539
if (additionalLeds[i] == 1 ) {
515
- strip.setPixelColor (i, color);
540
+ float saturation = random (0 , 100 ) / 100.0 ;
541
+ uint32_t newColor = color;
542
+ if (saturation < 0.5 && i <= 109 && nextLeds[i] != 1 ) {
543
+ newColor = saturateColor (color, saturation);
544
+ }
545
+
546
+ strip.setPixelColor (i, newColor);
516
547
}
517
548
}
518
549
519
550
strip.show ();
520
551
521
- delay (100 );
552
+ delay (130 );
522
553
}
523
554
}
524
555
0 commit comments