Skip to content

Commit b1908de

Browse files
committed
Adding example files.
1 parent ce3b86a commit b1908de

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

examples/led_animation_blink.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
This example blinks the LEDs purple at a 0.5 second interval.
3+
4+
For QT Py and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if using
5+
a different board or form of NeoPixels.
6+
7+
This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
8+
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
9+
"""
10+
import board
11+
import neopixel
12+
13+
from adafruit_led_animation.animation.blink import Blink
14+
from adafruit_led_animation.color import PURPLE
15+
16+
# Update to match the pin connected to your NeoPixels
17+
pixel_pin = board.A3
18+
# Update to match the number of NeoPixels you have connected
19+
pixel_num = 30
20+
21+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
22+
23+
blink = Blink(pixels, speed=0.5, color=PURPLE)
24+
25+
while True:
26+
blink.animate()

examples/led_animation_chase.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
This example animates a theatre chase style animation in white with a repeated 3 LEDs lit up at a
3+
spacing of six LEDs off.
4+
5+
For QT Py and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if using
6+
a different board or form of NeoPixels.
7+
8+
This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
9+
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
10+
"""
11+
import board
12+
import neopixel
13+
14+
from adafruit_led_animation.animation.chase import Chase
15+
from adafruit_led_animation.color import WHITE
16+
17+
# Update to match the pin connected to your NeoPixels
18+
pixel_pin = board.A3
19+
# Update to match the number of NeoPixels you have connected
20+
pixel_num = 30
21+
22+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
23+
24+
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
25+
26+
while True:
27+
chase.animate()

examples/led_animation_comet.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
This example animates a jade comet that bounces from end to end of the strip.
3+
4+
For QT Py and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if using
5+
a different board or form of NeoPixels.
6+
7+
This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
8+
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
9+
"""
10+
import board
11+
import neopixel
12+
13+
from adafruit_led_animation.animation.comet import Comet
14+
from adafruit_led_animation.color import JADE
15+
16+
# Update to match the pin connected to your NeoPixels
17+
pixel_pin = board.A3
18+
# Update to match the number of NeoPixels you have connected
19+
pixel_num = 30
20+
21+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
22+
23+
comet = Comet(pixels, speed=0.02, color=JADE, tail_length=10, bounce=True)
24+
25+
while True:
26+
comet.animate()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
This example shows how to reset the microcontroller to avoid the animation slowing down over time
3+
due to the limitations of CircuitPython for the SAMD21 (M0) microcontroller. The example
4+
animates a purple comet that bounces from end to end of the strip, and resets the board if the
5+
specified amount of time has passed since the board was last reset.
6+
7+
See this FAQ for details:
8+
9+
For QT Py and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if using
10+
a different board or form of NeoPixels.
11+
12+
This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
13+
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
14+
"""
15+
import time
16+
import microcontroller
17+
import board
18+
import neopixel
19+
20+
from adafruit_led_animation.animation.comet import Comet
21+
from adafruit_led_animation.color import PURPLE
22+
23+
# Update to match the pin connected to your NeoPixels
24+
pixel_pin = board.A3
25+
# Update to match the number of NeoPixels you have connected
26+
pixel_num = 30
27+
28+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
29+
30+
comet = Comet(pixels, speed=0.02, color=PURPLE, tail_length=10, bounce=True)
31+
32+
while True:
33+
comet.animate()
34+
35+
if time.monotonic() > 3600: # After an hour passes, reset the board.
36+
microcontroller.reset()

0 commit comments

Comments
 (0)