Tweaks, doc string added.
+"""Basic NeoPixel LED animations for the QT Py."""
import time
import board
import neopixel
@@ -13,25 +14,6 @@ pixels = neopixel.NeoPixel(pixel_pin, num_pixels, auto_write=False)
pixels.brightness = 0.2
-def color_wipe(color, wait):
- """Color wipe animation. Wipes across all pixels."""
- for pixel in range(num_pixels):
- pixels[pixel] = color
- time.sleep(wait)
- pixels.show()
- time.sleep(0.5)
-
-
-def rainbow_cycle(wait):
- """Rainbow cycle animation. Cycles across all pixels."""
- for color_index in range(255):
- for pixel in range(num_pixels):
- pixel_index = (pixel * 256 // num_pixels) + color_index
- pixels[pixel] = adafruit_pypixelbuf.colorwheel(pixel_index & 255)
- pixels.show()
- time.sleep(wait)
-
-
def blink(color, wait):
"""Blink animation. Blinks all pixels."""
pixels.fill(color)
@@ -65,6 +47,25 @@ def chase(color, spacing=3, iteration_step=1):
pixels[pixel + chase_pixel] = (0, 0, 0)
+def color_wipe(color, wait):
+ """Color wipe animation. Wipes across all pixels."""
+ for pixel in range(num_pixels):
+ pixels[pixel] = color
+ time.sleep(wait)
+ pixels.show()
+ time.sleep(0.5)
+
+
+def rainbow_cycle(wait):
+ """Rainbow cycle animation. Cycles across all pixels."""
+ for color_index in range(255):
+ for pixel in range(num_pixels):
+ pixel_index = (pixel * 256 // num_pixels) + color_index
+ pixels[pixel] = adafruit_pypixelbuf.colorwheel(pixel_index & 255)
+ pixels.show()
+ time.sleep(wait)
+
+
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
