Created
August 2, 2018 12:51
-
-
Save TheFlyingCorpse/cadecae373e1d7f9d047564f847a48de to your computer and use it in GitHub Desktop.
Fire / flicker neopixel ledstrip WS2812B
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Based off of http://www.walltech.cc/neopixel-fire-effect/ for Arduino | |
# Works with Raspbian Stretch on the RPi3 | |
import time | |
from neopixel import * | |
import argparse | |
# LED strip configuration: | |
LED_COUNT = 220 # Number of LED pixels. | |
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!). | |
#LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0). | |
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) | |
LED_DMA = 10 # DMA channel to use for generating signal (try 10) | |
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest | |
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) | |
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53 | |
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) | |
strip.begin() | |
while True: | |
r = 255; | |
g = 96; | |
b = 12; | |
for i in range(LED_COUNT): | |
flicker = random.randint(0,40) | |
r1 = r-flicker; | |
g1 = g-flicker; | |
b1 = b-flicker; | |
if r1<0: | |
r1 = 0; | |
if g1<0: | |
g1 = 0; | |
if b1<0: | |
b1 = 0; | |
strip.setPixelColor(i,Color(r1,g1,b1)) | |
strip.show() | |
time.sleep(random.uniform(0.05,0.15)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Next task: re-code for a matrix (eg 14x14) so every two lines get repeated (correct order / reversed per layout), and colour cools down for upper rows with random sparks of blue & white. ;-)