diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 017ce428..0247c7ef 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -108,14 +108,14 @@ void _generateBrightness() { // Scale white channel to match brightness _light_channel[3].value = constrain(_light_channel[3].value * LIGHT_WHITE_FACTOR, 0, 255); - // For the rest of channels, don't apply brightness, it is already in the inputValue: + // For the rest of channels, don't apply brightness, it is already in the target: for (unsigned char i=4; i < _light_channel.size(); i++) { _light_channel[i].value = _light_channel[i].inputValue; } } else { - // Don't apply brightness, it is already in the inputValue: + // Don't apply brightness, it is already in the target: for (unsigned char i=0; i < _light_channel.size(); i++) { if (_light_has_color & (i<3)) { _light_channel[i].value = _light_channel[i].inputValue * brightness; @@ -389,6 +389,7 @@ unsigned int _toPWM(unsigned char id) { } void _shadow() { + // Update transition ticker _light_steps_left--; if (_light_steps_left == 0) _light_transition_ticker.detach(); @@ -396,15 +397,20 @@ void _shadow() { // Transitions unsigned char target; for (unsigned int i=0; i < _light_channel.size(); i++) { - target = _light_state ? _light_channel[i].value : 0; + + target = _light_state && _light_channel[i].state ? _light_channel[i].value : 0; + if (_light_steps_left == 0) { _light_channel[i].current = target; } else { double difference = (double) (target - _light_channel[i].current) / (_light_steps_left + 1); _light_channel[i].current = _light_channel[i].current + difference; } + _light_channel[i].shadow = _light_channel[i].current; + } + } void _lightProviderUpdate() {