Skip to content

Commit 92e43c8

Browse files
authored
Merge pull request #1 from perryrh0dan/feat/transition
Feat/transition
2 parents c2bb3b5 + d6939db commit 92e43c8

File tree

2 files changed

+56
-24
lines changed

2 files changed

+56
-24
lines changed

.vscode/arduino.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"configuration": "xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,eesz=4M2M,led=2,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200",
33
"board": "esp8266:esp8266:nodemcuv2",
4-
"sketch": "main\\main.ino"
4+
"sketch": "main\\main.ino",
5+
"port": "COM4"
56
}

main/main.ino

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static String getDateTimeStringByParams(tm *newtime, char* pattern = (char *)"%d
5555
return buffer;
5656
}
5757

58-
static uint8_t splitColor ( uint32_t c, char value )
58+
static uint8_t splitRGBColor ( uint32_t c, char value )
5959
{
6060
switch ( value ) {
6161
case 'r': return (uint8_t)(c >> 16);
@@ -65,12 +65,23 @@ static uint8_t splitColor ( uint32_t c, char value )
6565
}
6666
}
6767

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+
6880
/**
6981
* Input time in epoch format format and return String with format pattern
7082
* by Renzo Mischianti <www.mischianti.org>
7183
*/
7284
static String getEpochStringByParams(long time, char* pattern = (char *)"%d/%m/%Y %I:%M:%S"){
73-
// struct tm *newtime;
7485
tm newtime;
7586
newtime = getDateTimeByParams(time);
7687
return getDateTimeStringByParams(&newtime, pattern);
@@ -87,6 +98,19 @@ static boolean isBetween(int value, int min, int max) {
8798
return false;
8899
}
89100

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+
90114
/**
91115
* Get led number by X and Y coordinates. 0/0 is bottom left.
92116
*/
@@ -103,8 +127,8 @@ struct time {
103127
uint8_t minute;
104128
};
105129

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);
108132

109133
uint8_t currentLeds[114];
110134
uint8_t nextLeds[114];
@@ -127,7 +151,7 @@ void setup() {
127151
}
128152

129153
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'));
131155
client.publish(STAT, "color", currentValue);
132156

133157
client.subscribe("color", [] (const String &payload) {
@@ -179,19 +203,12 @@ void loop() {
179203
setNextLeds(t.hour, t.minute);
180204

181205
if (currentTimeStamp % 5 == 0 || lastUpdate == 0) {
206+
Serial.println("Start transition");
182207
transition();
208+
} else {
209+
showNextLeds();
183210
}
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+
195212
lastUpdate = currentTimeStamp;
196213
}
197214

@@ -478,19 +495,21 @@ void transition() {
478495

479496
// Add all current active leds to the additionalLeds, they should be active till they are "hit" by the line in the same column
480497
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+
}
482501
}
483502

484503
// 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
487506
memset(interLeds, 0, sizeof(interLeds));
488507

489508
for (int col = 0; col < 11; col++) {
490509
for (int row = 0; row < lengths[col]; row++) {
491510
int led = getLedXY(col, startPositions[col] - i + row);
492511

493-
if (isBetween(led, 0, 110)) {
512+
if (isBetween(led, 0, 109)) {
494513
interLeds[led] = 1;
495514
}
496515
}
@@ -502,7 +521,13 @@ void transition() {
502521
if (interLeds[i] == 1) {
503522
additionalLeds[i] = 0;
504523

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);
506531
}
507532

508533
if (nextLeds[i] == 1) {
@@ -512,13 +537,19 @@ void transition() {
512537

513538
for(int i = 0; i < (sizeof(additionalLeds) / sizeof(additionalLeds[0])); i++) {
514539
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);
516547
}
517548
}
518549

519550
strip.show();
520551

521-
delay(100);
552+
delay(130);
522553
}
523554
}
524555

0 commit comments

Comments
 (0)