working with smooth fire colors and flicker refresh
This commit is contained in:
parent
01c999ebb4
commit
f22fd3393e
2 changed files with 9 additions and 25 deletions
Binary file not shown.
|
|
@ -1,10 +1,3 @@
|
||||||
# 'Cyber falls' sketch
|
|
||||||
# Creates a fiery rain-like effect on multiple NeoPixel strips.
|
|
||||||
# Requires Adafruit Trinket and NeoPixel strips. Strip length is
|
|
||||||
# inherently limited by Trinket RAM and processing power; this is
|
|
||||||
# written for five 15-pixel strands, which are paired up per pin
|
|
||||||
# for ten 15-pixel strips total.
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
|
|
@ -14,35 +7,26 @@ num_leds = 16 # number of LEDs per strip
|
||||||
saturation = 255 # 0-255, 0 is pure white, 255 is fully saturated color
|
saturation = 255 # 0-255, 0 is pure white, 255 is fully saturated color
|
||||||
blend = True # color blending between palette indices
|
blend = True # color blending between palette indices
|
||||||
brightness = 0.8 # brightness the range is 0.0 - 1.0
|
brightness = 0.8 # brightness the range is 0.0 - 1.0
|
||||||
concurrent = 16 # number of LEDs on at a time
|
offset = 0 # flame flicker
|
||||||
on_time = 0.04 # 0.04 seconds == 40 milliseconds
|
|
||||||
|
|
||||||
# NeoPixel objects using
|
# NeoPixel objects using
|
||||||
drop0 = neopixel.NeoPixel(board.D0, num_leds)
|
leds = neopixel.NeoPixel(board.D0, num_leds)
|
||||||
|
|
||||||
def led_drops(strip):
|
|
||||||
|
|
||||||
# FancyLED allows for mixing colors with palettes
|
|
||||||
palette = [fancy.CRGB(200, 255, 200), # lighter (more white) green
|
|
||||||
fancy.CRGB(0, 255, 0)] # full green
|
|
||||||
|
|
||||||
|
# Inspired by Fire2012() by Mark Kriegsman and his use of FastLED
|
||||||
|
# to create a one-dimensional 'fire' simulation
|
||||||
|
# the heat colors are from the heat palette that FastLED provides
|
||||||
|
def fire_2018(strip, offset):
|
||||||
# heat colors
|
# heat colors
|
||||||
palette = [0x330000, 0x660000, 0x990000, 0xCC0000, 0xFF0000,
|
palette = [0x330000, 0x660000, 0x990000, 0xCC0000, 0xFF0000,
|
||||||
0xFF3300, 0xFF6600, 0xFF9900, 0xFFCC00, 0xFFFF00,
|
0xFF3300, 0xFF6600, 0xFF9900, 0xFFCC00, 0xFFFF00,
|
||||||
0xFFFF33, 0xFFFF66, 0xFFFF99, 0xFFFFCC]
|
0xFFFF33, 0xFFFF66, 0xFFFF99, 0xFFFFCC]
|
||||||
|
|
||||||
|
|
||||||
for i in range(num_leds):
|
for i in range(num_leds):
|
||||||
# FancyLED can handle the gamma adjustment, brightness and RGB settings
|
# FancyLED can handle the gamma adjustment, brightness and RGB settings
|
||||||
color = fancy.palette_lookup(palette, i / num_leds)
|
color = fancy.palette_lookup(palette, offset + i / num_leds)
|
||||||
color = fancy.gamma_adjust(color, brightness=brightness)
|
color = fancy.gamma_adjust(color, brightness=brightness)
|
||||||
strip[i] = color.pack()
|
strip[i] = color.pack()
|
||||||
|
|
||||||
if i >= num_leds - 1:
|
|
||||||
for j in range(concurrent,-1,-1):
|
|
||||||
strip[i-j] = (0,0,0)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
fire_2018(leds, offset)
|
||||||
# loop through each neopixel strip in our list
|
offset += 0.3 # flame flicker, adjust value to control speed
|
||||||
led_drops(drop0)
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue