Skip to content

Commit 267aca5

Browse files
committed
Make the animation demo more like the standard arduino chase demo
This shows a phase shifted chase animation on each strip, each in a different color.
1 parent 4d15f21 commit 267aca5

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

examples/neopxl8_animations.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
#
33
# SPDX-License-Identifier: Unlicense
44

5-
# Set up a separate animation on each of 8 strips with NeoPxl8
6-
75
import board
8-
from adafruit_led_animation.animation.rainbow import Rainbow
6+
import rainbowio
7+
import adafruit_ticks
98
from adafruit_led_animation.animation.comet import Comet
10-
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
11-
from adafruit_led_animation.animation.rainbowchase import RainbowChase
12-
from adafruit_led_animation.animation.chase import Chase
139
from adafruit_led_animation.group import AnimationGroup
1410
from adafruit_led_animation.helper import PixelMap
15-
from adafruit_led_animation import color
1611
from adafruit_neopxl8 import NeoPxl8
1712

1813
# Customize for your strands here
@@ -28,30 +23,43 @@
2823
num_pixels,
2924
num_strands=num_strands,
3025
auto_write=False,
31-
brightness=0.07,
26+
brightness=0.50,
3227
)
3328

3429

35-
def strand(i):
30+
def strand(n):
3631
return PixelMap(
3732
pixels,
38-
range(i * strand_length, (i + 1) * strand_length),
33+
range(n * strand_length, (n + 1) * strand_length),
3934
individual_pixels=True,
4035
)
4136

4237

38+
# Create the 8 virtual strands
4339
strands = [strand(i) for i in range(num_strands)]
4440

45-
animations = AnimationGroup(
46-
Comet(strands[0], 0.5, color.CYAN),
47-
Comet(strands[1], 0.4, color.AMBER),
48-
RainbowComet(strands[2], 0.3),
49-
RainbowComet(strands[3], 0.7),
50-
Chase(strands[4], 0.05, size=2, spacing=3, color=color.PURPLE),
51-
RainbowChase(strands[5], 0.05, size=2, spacing=3),
52-
Rainbow(strands[6], 0.6),
53-
Rainbow(strands[7], 0.23, step=21),
54-
)
41+
# For each strand, create a comet animation of a different color
42+
animations = [
43+
Comet(strand, 0.02, rainbowio.colorwheel(3 * 32 * i), ring=True)
44+
for i, strand in enumerate(strands)
45+
]
46+
47+
# Advance the animations by varying amounts so that they become staggered
48+
for i, animation in enumerate(animations):
49+
animation._tail_start = 30 * 5 * i // 8 # pylint: disable=protected-access
50+
51+
# Group them so we can run them all at once
52+
animations = AnimationGroup(*animations)
5553

54+
# Run the animations and report on the speed in frame per secodn
55+
t0 = adafruit_ticks.ticks_ms()
56+
frame_count = 0
5657
while True:
5758
animations.animate()
59+
frame_count += 1
60+
t1 = adafruit_ticks.ticks_ms()
61+
dt = adafruit_ticks.ticks_diff(t1, t0)
62+
if dt > 1000:
63+
print(f"{frame_count * 1000/dt:.1f}fps")
64+
t0 = t1
65+
frame_count = 0

0 commit comments

Comments
 (0)