Simple test¶
Ensure your device works with this simple test.
examples/fancyled_neopixel_rotate_simpletest.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
""" Simple FancyLED example for NeoPixel strip
"""
import board
import neopixel
import adafruit_fancyled.adafruit_fancyled as fancy
num_leds = 20
# Declare a 6-element RGB rainbow palette
palette = [
    fancy.CRGB(1.0, 0.0, 0.0),  # Red
    fancy.CRGB(0.5, 0.5, 0.0),  # Yellow
    fancy.CRGB(0.0, 1.0, 0.0),  # Green
    fancy.CRGB(0.0, 0.5, 0.5),  # Cyan
    fancy.CRGB(0.0, 0.0, 1.0),  # Blue
    fancy.CRGB(0.5, 0.0, 0.5),
]  # Magenta
# Declare a NeoPixel object on pin D6 with num_leds pixels, no auto-write.
# Set brightness to max because we'll be using FancyLED's brightness control.
pixels = neopixel.NeoPixel(board.D6, num_leds, brightness=1.0, auto_write=False)
offset = 0  # Positional offset into color palette to get it to 'spin'
while True:
    for i in range(num_leds):
        # Load each pixel's color from the palette using an offset, run it
        # through the gamma function, pack RGB value and assign to pixel.
        color = fancy.palette_lookup(palette, offset + i / num_leds)
        color = fancy.gamma_adjust(color, brightness=0.25)
        pixels[i] = color.pack()
    pixels.show()
    offset += 0.02  # Bigger number = faster spin
 | 
examples/fancyled_cpx_helper_example.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
""" FancyLED example for Circuit Playground Express using fastled_helpers
"""
from adafruit_circuitplayground.express import cpx
import adafruit_fancyled.fastled_helpers as helper
cpx.pixels.auto_write = False  # Refresh pixels only when we say
# A dynamic gradient palette is a compact way of representing a palette with
# non-equal spacing between elements.  This one's a blackbody palette with a
# longer red 'tail'.  The helper functions let us declare this as a list of
# bytes, so they're easier to copy over from existing FastLED projects.
# fmt: off
heatmap_gp = bytes([
    0, 255, 255, 255,  # White
    64, 255, 255, 0,  # Yellow
    128, 255, 0, 0,  # Red
    255, 0, 0, 0])  # Black
# fmt: on
# Convert the gradient palette into a normal palette w/16 elements:
palette = helper.loadDynamicGradientPalette(heatmap_gp, 16)
offset = 0  # Positional offset into color palette to get it to 'spin'
while True:
    for i in range(10):
        # Load each pixel's color from the palette.  FastLED uses 16-step
        # in-between blending...so for a 16-color palette, there's 256
        # steps total.  With 10 pixels, multiply the pixel index by 25.5
        # (and add our offset) to get FastLED-style palette position.
        color = helper.ColorFromPalette(palette, int(offset + i * 25.5), blend=True)
        # Apply gamma using the FastLED helper syntax
        color = helper.applyGamma_video(color)
        # 'Pack' color and assign to NeoPixel #i
        cpx.pixels[i] = color.pack()
    cpx.pixels.show()
    offset += 8  # Bigger number = faster spin
 | 
examples/fancyled_cpx_rotate.py¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
""" Simple FancyLED example for Circuit Playground Express
"""
from adafruit_circuitplayground.express import cpx
import adafruit_fancyled.adafruit_fancyled as fancy
cpx.pixels.auto_write = False  # Refresh pixels only when we say
cpx.pixels.brightness = 1.0  # We'll use FancyLED's brightness controls
# Declare a 4-element color palette, this one happens to be a
# 'blackbody' palette -- good for heat maps and firey effects.
palette = [
    fancy.CRGB(1.0, 1.0, 1.0),  # White
    fancy.CRGB(1.0, 1.0, 0.0),  # Yellow
    fancy.CRGB(1.0, 0.0, 0.0),  # Red
    fancy.CRGB(0.0, 0.0, 0.0),
]  # Black
offset = 0  # Positional offset into color palette to get it to 'spin'
levels = (0.25, 0.3, 0.15)  # Color balance / brightness for gamma function
while True:
    for i in range(10):
        # Load each pixel's color from the palette using an offset, run it
        # through the gamma function, pack RGB value and assign to pixel.
        color = fancy.palette_lookup(palette, offset + i / 10)
        color = fancy.gamma_adjust(color, brightness=levels)
        cpx.pixels[i] = color.pack()
    cpx.pixels.show()
    offset += 0.033  # Bigger number = faster spin
 |