|
2 | 2 | #
|
3 | 3 | # SPDX-License-Identifier: Unlicense
|
4 | 4 |
|
5 |
| -# Set up a separate animation on each of 8 strips with NeoPxl8 |
6 |
| - |
7 | 5 | import board
|
8 |
| -from adafruit_led_animation.animation.rainbow import Rainbow |
| 6 | +import rainbowio |
| 7 | +import adafruit_ticks |
9 | 8 | 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 |
13 | 9 | from adafruit_led_animation.group import AnimationGroup
|
14 | 10 | from adafruit_led_animation.helper import PixelMap
|
15 |
| -from adafruit_led_animation import color |
16 | 11 | from adafruit_neopxl8 import NeoPxl8
|
17 | 12 |
|
18 | 13 | # Customize for your strands here
|
|
28 | 23 | num_pixels,
|
29 | 24 | num_strands=num_strands,
|
30 | 25 | auto_write=False,
|
31 |
| - brightness=0.07, |
| 26 | + brightness=0.50, |
32 | 27 | )
|
33 | 28 |
|
34 | 29 |
|
35 |
| -def strand(i): |
| 30 | +def strand(n): |
36 | 31 | return PixelMap(
|
37 | 32 | pixels,
|
38 |
| - range(i * strand_length, (i + 1) * strand_length), |
| 33 | + range(n * strand_length, (n + 1) * strand_length), |
39 | 34 | individual_pixels=True,
|
40 | 35 | )
|
41 | 36 |
|
42 | 37 |
|
| 38 | +# Create the 8 virtual strands |
43 | 39 | strands = [strand(i) for i in range(num_strands)]
|
44 | 40 |
|
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) |
55 | 53 |
|
| 54 | +# Run the animations and report on the speed in frame per secodn |
| 55 | +t0 = adafruit_ticks.ticks_ms() |
| 56 | +frame_count = 0 |
56 | 57 | while True:
|
57 | 58 | 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