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