Skip to content

Instantly share code, notes, and snippets.

@emwdx
Created May 26, 2022 06:01
Show Gist options
  • Save emwdx/89432756ab17f62727984ef8576d1124 to your computer and use it in GitHub Desktop.
Save emwdx/89432756ab17f62727984ef8576d1124 to your computer and use it in GitHub Desktop.
SSIS Prom Flickering Neopixel Vase Light
"""This code is based on the Jack-o'-Lantern flame example for Adafruit Circuit Playground Express"""
""" Modified by Evan Weinberg to flicker a bright white light value for a stick of 8 Neopixels
import math
import board
import neopixel
try:
import urandom as random # for v1.0 API support
except ImportError:
import random
NUMPIX = 8 # Number of NeoPixels
PIXPIN = board.D8 # Pin where NeoPixels are connected
STRIP = neopixel.NeoPixel(PIXPIN, NUMPIX, brightness=1.0)
PREV = 128
def split(first, second, offset):
"""
Subdivide a brightness range, introducing a random offset in middle,
then call recursively with smaller offsets along the way.
@param1 first: Initial brightness value.
@param1 second: Ending brightness value.
@param1 offset: Midpoint offset range is +/- this amount max.
"""
if offset != 0:
mid = ((first + second + 1) / 2 + random.randint(-offset, offset))
offset = int(offset / 2)
split(first, mid, offset)
split(mid, second, offset)
else:
level = math.pow(first / 255.0, 2.7) * 255.0 + 0.95
STRIP.fill((int(level ), int(level ), int(level)))
STRIP.write()
while True: # Loop forever...
LVL = random.randint(64, 191)
split(PREV, LVL, 32)
PREV = LVL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment