Last active
October 31, 2020 04:46
-
-
Save deslee/b6acfee157ad1df611e46823e671e6e1 to your computer and use it in GitHub Desktop.
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
# Simple test for NeoPixels on Raspberry Pi | |
import threading | |
import board | |
import neopixel | |
import colorsys | |
from random import randint | |
def hsv2rgb(h,s,v): | |
return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h,s,v)) | |
# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18 | |
# NeoPixels must be connected to D10, D12, D18 or D21 to work. | |
pixel_pin = board.D18 | |
# The number of NeoPixels | |
num_pixels = 300 | |
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed! | |
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW. | |
ORDER = neopixel.RGB | |
pixels = neopixel.NeoPixel( | |
pixel_pin, num_pixels, brightness=0.2, auto_write=False | |
) | |
black = (0,0,0) | |
pixels.fill(black) | |
hue = 0 | |
pixels.show() | |
def fadeToBlackBy(pixel, multiplier): | |
return ( int(pixel[0] * multiplier), int(pixel[1] * multiplier), int(pixel[2] * multiplier) ) | |
def confetti(): | |
# fade | |
for position in range(num_pixels): | |
pixel = pixels[position] | |
pixels[position] = fadeToBlackBy(pixels[position], .95) | |
pos = randint(0, num_pixels-1) | |
color = hsv2rgb( (int(randint(0, 65) + hue)) % 360 / 360, 200/255, 255/255 ) | |
pixels[pos] = color | |
pixels.show() | |
def increment_hue(): | |
global hue | |
threading.Timer(.02, increment_hue).start() | |
hue = hue + 1 | |
increment_hue() | |
while True: | |
confetti() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment