From 6fd667b1cac6e764e3ba94942cb576e4f9607adf Mon Sep 17 00:00:00 2001 From: Ray Bellis Date: Wed, 13 Dec 2023 21:43:01 +0000 Subject: [PATCH 1/2] fix hue errors in plasma_stick_rainbows --- examples/plasma_stick/plasma_stick_rainbows.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/plasma_stick/plasma_stick_rainbows.cpp b/examples/plasma_stick/plasma_stick_rainbows.cpp index d068d4e9..faa84e41 100644 --- a/examples/plasma_stick/plasma_stick_rainbows.cpp +++ b/examples/plasma_stick/plasma_stick_rainbows.cpp @@ -34,10 +34,15 @@ int main() { while(true) { offset += float(SPEED) / 2000.0f; + if (offset > 1.0) { + offset -= 1.0; + } for(auto i = 0u; i < NUM_LEDS; ++i) { float hue = float(i) / NUM_LEDS; - led_strip.set_hsv(i, hue + offset, 1.0f, 1.0f); + hue += offset; + hue -= floor(hue); + led_strip.set_hsv(i, hue, 1.0f, 1.0f); } sleep_ms(1000 / UPDATES); From da0ac1821f2be8388fc5421b695c9a19a6af7442 Mon Sep 17 00:00:00 2001 From: Ray Bellis Date: Tue, 2 Jan 2024 22:22:09 +0000 Subject: [PATCH 2/2] resolve precision error in python example too --- micropython/examples/plasma_stick/rainbows.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/micropython/examples/plasma_stick/rainbows.py b/micropython/examples/plasma_stick/rainbows.py index 5c0b5ea9..dc6d52bc 100644 --- a/micropython/examples/plasma_stick/rainbows.py +++ b/micropython/examples/plasma_stick/rainbows.py @@ -28,9 +28,10 @@ while True: SPEED = min(255, max(1, SPEED)) offset += float(SPEED) / 2000.0 + offset %= 1 for i in range(NUM_LEDS): - hue = float(i) / NUM_LEDS + hue = (offset + float(i) / NUM_LEDS) % 1 led_strip.set_hsv(i, hue + offset, 1.0, 1.0) time.sleep(1.0 / UPDATES)