Circuit Playground Express Comet

Continuing on with experimenting with the Adafruit Circuit Playground Express and the NeoPixels, I found a nice example of a rotating colour wheel or comet as I like to think about it. The lead LED is white and circles around the board trailing a "tail" of gradually cooling colours behind it.

circuit playground showing LEDs lit in red

I modified it slightly to add more red colours into the palette from the original so that it both has a longer tail and it burns out into darker colours. The spin rate determines the speed of the rotation of the "comet" around the board.

Code


# comet.py

from adafruit_circuitplayground.express import cpx
import adafruit_fancyled.adafruit_fancyled as fancy

cpx.pixels.auto_write = False  
cpx.pixels.brightness = 0.25   

palette = [fancy.CRGB(255, 255, 255),  
           fancy.CRGB(255, 255, 0),   
           fancy.CRGB(255, 0, 0),     
           fancy.CRGB(128,0,0),
           fancy.CRGB(64,0,0),
           fancy.CRGB(32,0,0),
           fancy.CRGB(16,0,0),
           fancy.CRGB(8,0,0),
           fancy.CRGB(0,0,0)
           ]          

offset = 0  
spin_rate = 0.03

while True:
    for i in range(10):
        color = fancy.palette_lookup(palette, offset + i / 9)
        cpx.pixels[i] = color.pack()
       
    cpx.pixels.show()

    offset += spin_rate