From 7c68d7a754a06f56c7178e41cb4b4fae9756bbc1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 8 Jan 2020 17:45:48 +0100 Subject: [PATCH] Improve random color cycle for scheme 4 Improve random color cycle for scheme 4 (#7273) --- tasmota/xdrv_04_light.ino | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index df65b1591..5cbcecdfa 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1613,13 +1613,15 @@ void LightCycleColor(int8_t direction) if (Light.random == Light.wheel) { Light.random = random(255); - uint8_t my_dir = ((Light.random < Light.wheel -128) || (Light.random > Light.wheel +128)) ? 1 : 0; - Light.random |= my_dir; + uint8_t my_dir = (Light.random < Light.wheel -128) ? 1 : + (Light.random < Light.wheel ) ? 0 : + (Light.random > Light.wheel +128) ? 0 : 1; // Increment or Decrement and roll-over + Light.random = (Light.random & 0xFE) | my_dir; // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("LGT: random %d"), Light.random); } // direction = (Light.random < Light.wheel) ? -1 : 1; - direction = (Light.random &1) ? -1 : 1; + direction = (Light.random &0x01) ? 1 : -1; } Light.wheel += direction; uint16_t hue = changeUIntScale(Light.wheel, 0, 255, 0, 359); // Scale to hue to keep amount of steps low (max 255 instead of 359)