Skip to content

Instantly share code, notes, and snippets.

@lizzybrooks
Created February 11, 2023 00:16
Show Gist options
  • Save lizzybrooks/3e8322edb98d2519d377575513ce9964 to your computer and use it in GitHub Desktop.
Save lizzybrooks/3e8322edb98d2519d377575513ce9964 to your computer and use it in GitHub Desktop.
import board
import neopixel
import time
pixel_pin = board.D2 #the ring data is connected to this pin
num_pixels = 16 #number of leds pixels on the ring
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
MOST = (245, 24, 113) #RGB
SECOND = (247, 47, 128)
MIDDLE = (250, 82, 150)
LIGHTER = (245, 110, 164)
LIGHT = (250, 125, 176)
LIGHTEST = (250, 150, 191)
OFF = (0,0,0)
# helper function for fading - do not touch
def fade(c1, c2):
diff = (c2[0]-c1[0], c2[1]-c1[1], c2[2]-c1[2])
diffA = [1 if n==0 else abs(n) for n in diff]
maxDiff = max(diffA)
index = diffA.index(maxDiff)
cFade = list(c1)
increment = [int(diff[i]/diffA[i]) for i in range(3)]
for i in range(0, maxDiff):
for n in range(3):
if(cFade[n] != c2[n]):
cFade[n] += increment[n]
pixels.fill(tuple(cFade))
pixels.show()
time.sleep(0.01) # debounce delay
for light in range(0,16,1):
pixels[light]=MOST
pixels.show()
time.sleep(1)
fade(MOST, SECOND)
fade(SECOND, MIDDLE)
fade(MIDDLE, LIGHTER)
fade(LIGHTER, LIGHT)
fade(LIGHT, LIGHTEST)
time.sleep(0.5) # debounce delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment