fancyled_cpx_helper_example.py
1 """ FancyLED example for Circuit Playground Express using fastled_helpers 2 """ 3 4 from adafruit_circuitplayground.express import cpx 5 import adafruit_fancyled.fastled_helpers as helper 6 7 cpx.pixels.auto_write = False # Refresh pixels only when we say 8 9 # A dynamic gradient palette is a compact way of representing a palette with 10 # non-equal spacing between elements. This one's a blackbody palette with a 11 # longer red 'tail'. The helper functions let us declare this as a list of 12 # bytes, so they're easier to copy over from existing FastLED projects. 13 # fmt: off 14 heatmap_gp = bytes([ 15 0, 255, 255, 255, # White 16 64, 255, 255, 0, # Yellow 17 128, 255, 0, 0, # Red 18 255, 0, 0, 0]) # Black 19 # fmt: on 20 21 # Convert the gradient palette into a normal palette w/16 elements: 22 palette = helper.loadDynamicGradientPalette(heatmap_gp, 16) 23 24 offset = 0 # Positional offset into color palette to get it to 'spin' 25 26 while True: 27 for i in range(10): 28 # Load each pixel's color from the palette. FastLED uses 16-step 29 # in-between blending...so for a 16-color palette, there's 256 30 # steps total. With 10 pixels, multiply the pixel index by 25.5 31 # (and add our offset) to get FastLED-style palette position. 32 color = helper.ColorFromPalette(palette, int(offset + i * 25.5), blend=True) 33 # Apply gamma using the FastLED helper syntax 34 color = helper.applyGamma_video(color) 35 # 'Pack' color and assign to NeoPixel #i 36 cpx.pixels[i] = color.pack() 37 cpx.pixels.show() 38 39 offset += 8 # Bigger number = faster spin