Circuit Playground Express Comet

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.



from 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),     

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()

    offset += spin_rate