Skip to content

Commit cc9a07e

Browse files
Merge pull request #34 from techniccontroller/dev_dyncolorshift
Add dynamic color shift feature
2 parents 62e6aec + 697cfd2 commit cc9a07e

File tree

5 files changed

+199
-92
lines changed

5 files changed

+199
-92
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Thank you to everyone who provided feedback on adding new languages and testing
2626
- webserver interface for configuration and control
2727
- physical button to change mode or enable night mode without webserver
2828
- automatic current limiting of LEDs
29+
- dynamic color shift mode
2930

3031
## Pictures of clock
3132
![modes_images2](https://user-images.githubusercontent.com/36072504/156947689-dd90874d-a887-4254-bede-4947152d85c1.png)
@@ -152,7 +153,7 @@ MCAST_IF_IP = '192.168.0.7'
152153
4. Execute the script with following command:
153154

154155
```bash
155-
python multicastUDP_receiver_analyzer.py
156+
python multicastUDP_receiver.py
156157
```
157158

158159
5. Now you should see the log messages of the word clock (every 5 seconds a heartbeat message and the currently displayed time).

data/index.html

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
}
244244

245245
.show{
246-
height: 200px;
246+
height: 230px;
247247
transition: height 1s;
248248
}
249249

@@ -276,6 +276,10 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
276276
<label for="brightness">Brightness:</label>
277277
<input type="range" id="brightness" name="volume" min="10" max="255">
278278
</div>
279+
<div class="number-container">
280+
<label for="colorshiftspeed">Color shift speed:</label>
281+
<input type="range" id="colorshiftspeed" name="volume" min="0" max="50">
282+
</div>
279283
<div class="number-container">
280284
<label for="nm_start" style="align-self: flex-start">Nightmode start time: </label>
281285
<input type="time" id="nm_start" name="nm_start" min="00:00" max="23:59">
@@ -317,7 +321,12 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
317321
<div>
318322
<input name= "AutoChange" id="AutoChange" type="checkbox" class="toggle">
319323
</div>
320-
324+
</div>
325+
<div class="checkbox-container" id = "colorshiftcontainer">
326+
<label for="ColorShift" style="align-self: flex-start">DynamicColorShift</label>
327+
<div>
328+
<input name= "ColorShift" id="ColorShift" type="checkbox" class="toggle">
329+
</div>
321330
</div>
322331

323332
<div class="main-container hidden" id="colorcontainer">
@@ -480,10 +489,28 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
480489
sendCommand("./cmd?stateautochange=0");
481490
}
482491
});
492+
493+
var ckb_colorshift = document.querySelector('input[id="ColorShift"]');
494+
if(myVar.colorshift == "1") {
495+
console.log("colorshift == 1");
496+
ckb_colorshift.checked = true;
497+
}
498+
else {
499+
console.log("colorshift == 0");
500+
ckb_colorshift.checked = false;
501+
}
502+
ckb_colorshift.addEventListener('change', () => {
503+
if(ckb_colorshift.checked) {
504+
sendCommand("./cmd?colorshift=1");
505+
} else {
506+
sendCommand("./cmd?colorshift=0");
507+
}
508+
});
483509

484510
document.getElementById("nm_start").value = myVar.nightModeStart.replace("-", ":");
485511
document.getElementById("nm_end").value = myVar.nightModeEnd.replace("-", ":");
486512
document.getElementById("brightness").value = parseInt(myVar.brightness);
513+
document.getElementById("colorshiftspeed").value = parseInt(myVar.colorshiftspeed);
487514

488515
updateDisplay(parseInt(myVar.modeid));
489516
console.log(myVar);
@@ -513,20 +540,26 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
513540
switch(modeid){
514541
case 0: // clock
515542
document.getElementById("colorcontainer").classList.remove("hidden");
543+
document.getElementById("colorshiftcontainer").classList.remove("hidden");
516544
break;
517545
case 1: // diclock
518546
document.getElementById("colorcontainer").classList.remove("hidden");
547+
document.getElementById("colorshiftcontainer").classList.add("hidden");
519548
break;
520549
case 2: // spiral
550+
document.getElementById("colorshiftcontainer").classList.add("hidden");
521551
break;
522552
case 3: // tetris
523553
document.getElementById("tetriscontainer").classList.remove("hidden");
554+
document.getElementById("colorshiftcontainer").classList.add("hidden");
524555
break;
525556
case 4: // snake
526557
document.getElementById("snakecontainer").classList.remove("hidden");
558+
document.getElementById("colorshiftcontainer").classList.add("hidden");
527559
break;
528560
case 5: // pingping
529561
document.getElementById("pongcontainer").classList.remove("hidden");
562+
document.getElementById("colorshiftcontainer").classList.add("hidden");
530563
break;
531564

532565
}
@@ -543,14 +576,17 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
543576
function saveSettings(){
544577
var nmStart = document.getElementById("nm_start");
545578
var nmEnd = document.getElementById("nm_end");
546-
var brightnessElmt = document.getElementById("brightness");
579+
var sld_brightness = document.getElementById("brightness");
580+
var sld_colorshiftspeed = document.getElementById("colorshiftspeed");
547581
var ckb_resetWifi = document.querySelector('input[id="ResetWifi"]');
548582
var cmdstr = "./cmd?setting=";
549583
cmdstr += nmStart.value.replace(":", "-");
550584
cmdstr += "-";
551585
cmdstr += nmEnd.value.replace(":", "-");
552586
cmdstr += "-";
553-
cmdstr += brightnessElmt.value;
587+
cmdstr += sld_brightness.value;
588+
cmdstr += "-";
589+
cmdstr += sld_colorshiftspeed.value;
554590
console.log(cmdstr);
555591
sendCommand(cmdstr);
556592
if(ckb_resetWifi.checked) {

ledmatrix.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ void LEDMatrix::setupMatrix()
104104
*/
105105
void LEDMatrix::setMinIndicator(uint8_t pattern, uint32_t color)
106106
{
107+
if(dynamicColorShiftActivePhase >= 0){
108+
color = Wheel(dynamicColorShiftActivePhase);
109+
}
107110
// pattern:
108111
// 15 -> 1111
109112
// 14 -> 1110
@@ -134,6 +137,9 @@ void LEDMatrix::setMinIndicator(uint8_t pattern, uint32_t color)
134137
*/
135138
void LEDMatrix::gridAddPixel(uint8_t x, uint8_t y, uint32_t color)
136139
{
140+
if(dynamicColorShiftActivePhase >= 0){
141+
color = Wheel((uint16_t(x + y*WIDTH) * 256 * 2 / (WIDTH*HEIGHT) + dynamicColorShiftActivePhase) % 256);
142+
}
137143
// limit ranges of x and y
138144
if(x < WIDTH && y < HEIGHT){
139145
targetgrid[y][x] = color;
@@ -298,4 +304,14 @@ uint16_t LEDMatrix::calcEstimatedLEDCurrent(uint32_t color){
298304
*/
299305
void LEDMatrix::setCurrentLimit(uint16_t mycurrentLimit){
300306
currentLimit = mycurrentLimit;
307+
}
308+
309+
/**
310+
* @brief Set dynamic color shift phase (0-255)
311+
*
312+
* @param phase phase of the color shift
313+
*/
314+
void LEDMatrix::setDynamicColorShiftPhase(int16_t phase)
315+
{
316+
dynamicColorShiftActivePhase = phase;
301317
}

ledmatrix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class LEDMatrix{
3030
void printChar(uint8_t xpos, uint8_t ypos, char character, uint32_t color);
3131
void setBrightness(uint8_t mybrightness);
3232
void setCurrentLimit(uint16_t mycurrentLimit);
33+
void setDynamicColorShiftPhase(int16_t phase);
3334

3435
private:
3536

@@ -38,6 +39,7 @@ class LEDMatrix{
3839

3940
uint8_t brightness;
4041
uint16_t currentLimit;
42+
int16_t dynamicColorShiftActivePhase = -1; // -1: not active, 0-255: active phase shift
4143

4244
// target representation of matrix as 2D array
4345
uint32_t targetgrid[HEIGHT][WIDTH] = {0};

0 commit comments

Comments
 (0)