|
| 1 | +# SPDX-FileCopyrightText: 2024 Tim Cocks |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Unlicense |
| 4 | + |
| 5 | +import board |
| 6 | +import adafruit_ticks |
| 7 | +from adafruit_led_animation.animation.sparklepulse import SparklePulse |
| 8 | +from adafruit_led_animation.animation.comet import Comet |
| 9 | +from adafruit_led_animation.animation.chase import Chase |
| 10 | +from adafruit_led_animation.animation.pulse import Pulse |
| 11 | +from adafruit_led_animation.animation.sparkle import Sparkle |
| 12 | +from adafruit_led_animation.animation.rainbowchase import RainbowChase |
| 13 | +from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle |
| 14 | +from adafruit_led_animation.animation.rainbowcomet import RainbowComet |
| 15 | +from adafruit_led_animation.group import AnimationGroup |
| 16 | +from adafruit_led_animation.helper import PixelMap |
| 17 | +from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE |
| 18 | +from adafruit_neopxl8 import NeoPxl8 |
| 19 | + |
| 20 | +# Customize for your strands here |
| 21 | +num_strands = 8 |
| 22 | +strand_length = 30 |
| 23 | +first_led_pin = board.NEOPIXEL0 |
| 24 | + |
| 25 | +num_pixels = num_strands * strand_length |
| 26 | + |
| 27 | +# Make the object to control the pixels |
| 28 | +pixels = NeoPxl8( |
| 29 | + first_led_pin, |
| 30 | + num_pixels, |
| 31 | + num_strands=num_strands, |
| 32 | + auto_write=False, |
| 33 | + brightness=0.1, |
| 34 | +) |
| 35 | + |
| 36 | + |
| 37 | +def strand(n): |
| 38 | + return PixelMap( |
| 39 | + pixels, |
| 40 | + range(n * strand_length, (n + 1) * strand_length), |
| 41 | + individual_pixels=True, |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +# Create the 8 virtual strands |
| 46 | +strands = [strand(i) for i in range(num_strands)] |
| 47 | + |
| 48 | +# For each strand, create a comet animation of a different color |
| 49 | +animations = [ |
| 50 | + Comet(strands[0], speed=0.01, color=PURPLE, tail_length=10, bounce=True), |
| 51 | + Chase(strands[1], speed=0.1, size=3, spacing=6, color=WHITE), |
| 52 | + Pulse(strands[2], speed=0.1, period=3, color=AMBER), |
| 53 | + Sparkle(strands[3], speed=0.1, color=PURPLE, num_sparkles=10), |
| 54 | + SparklePulse(strands[4], speed=0.1, period=3, color=JADE), |
| 55 | + RainbowComet(strands[5], speed=0.1, tail_length=7, bounce=True), |
| 56 | + RainbowChase(strands[6], speed=0.1, size=3, spacing=2, step=8), |
| 57 | + RainbowSparkle(strands[7], speed=0.1, num_sparkles=15), |
| 58 | +] |
| 59 | + |
| 60 | +# Group them so we can run them all at once |
| 61 | +animations = AnimationGroup(*animations) |
| 62 | + |
| 63 | +# Run the animations and report on the speed in frame per second |
| 64 | +t0 = adafruit_ticks.ticks_ms() |
| 65 | +frame_count = 0 |
| 66 | +while True: |
| 67 | + animations.animate() |
| 68 | + frame_count += 1 |
| 69 | + t1 = adafruit_ticks.ticks_ms() |
| 70 | + dt = adafruit_ticks.ticks_diff(t1, t0) |
| 71 | + if dt > 1000: |
| 72 | + print(f"{frame_count * 1000/dt:.1f}fps") |
| 73 | + t0 = t1 |
| 74 | + frame_count = 0 |
0 commit comments