fancyled_neopixel_rotate_simpletest.py
1 """ Simple FancyLED example for NeoPixel strip 2 """ 3 4 import board 5 import neopixel 6 import adafruit_fancyled.adafruit_fancyled as fancy 7 8 num_leds = 20 9 10 # Declare a 6-element RGB rainbow palette 11 palette = [ 12 fancy.CRGB(1.0, 0.0, 0.0), # Red 13 fancy.CRGB(0.5, 0.5, 0.0), # Yellow 14 fancy.CRGB(0.0, 1.0, 0.0), # Green 15 fancy.CRGB(0.0, 0.5, 0.5), # Cyan 16 fancy.CRGB(0.0, 0.0, 1.0), # Blue 17 fancy.CRGB(0.5, 0.0, 0.5), 18 ] # Magenta 19 20 # Declare a NeoPixel object on pin D6 with num_leds pixels, no auto-write. 21 # Set brightness to max because we'll be using FancyLED's brightness control. 22 pixels = neopixel.NeoPixel(board.D6, num_leds, brightness=1.0, auto_write=False) 23 24 offset = 0 # Positional offset into color palette to get it to 'spin' 25 26 while True: 27 for i in range(num_leds): 28 # Load each pixel's color from the palette using an offset, run it 29 # through the gamma function, pack RGB value and assign to pixel. 30 color = fancy.palette_lookup(palette, offset + i / num_leds) 31 color = fancy.gamma_adjust(color, brightness=0.25) 32 pixels[i] = color.pack() 33 pixels.show() 34 35 offset += 0.02 # Bigger number = faster spin