Skip to content

Commit 0d3fce9

Browse files
authored
Merge pull request #883 from raybellis/main
fix hue errors in plasma_stick_rainbows
2 parents bff2453 + da0ac18 commit 0d3fce9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

examples/plasma_stick/plasma_stick_rainbows.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ int main() {
3434
while(true) {
3535

3636
offset += float(SPEED) / 2000.0f;
37+
if (offset > 1.0) {
38+
offset -= 1.0;
39+
}
3740

3841
for(auto i = 0u; i < NUM_LEDS; ++i) {
3942
float hue = float(i) / NUM_LEDS;
40-
led_strip.set_hsv(i, hue + offset, 1.0f, 1.0f);
43+
hue += offset;
44+
hue -= floor(hue);
45+
led_strip.set_hsv(i, hue, 1.0f, 1.0f);
4146
}
4247

4348
sleep_ms(1000 / UPDATES);

micropython/examples/plasma_stick/rainbows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828

2929
SPEED = min(255, max(1, SPEED))
3030
offset += float(SPEED) / 2000.0
31+
offset %= 1
3132

3233
for i in range(NUM_LEDS):
33-
hue = float(i) / NUM_LEDS
34+
hue = (offset + float(i) / NUM_LEDS) % 1
3435
led_strip.set_hsv(i, hue + offset, 1.0, 1.0)
3536

3637
time.sleep(1.0 / UPDATES)

0 commit comments

Comments
 (0)