kopia lustrzana https://github.com/blaz-r/pi_pico_neopixel
added examples
rodzic
3b6bfaf8f8
commit
fc7406dfda
|
@ -0,0 +1,41 @@
|
|||
# Example showing how functions, that accept tuples of rgb values,
|
||||
# simplify working with gradients
|
||||
|
||||
import time
|
||||
from neopixel import neopixel
|
||||
|
||||
numpix = 60
|
||||
strip = neopixel(numpix, 1, 1, "RGB")
|
||||
|
||||
red = (255, 0, 0)
|
||||
orange = (255, 50, 0)
|
||||
yellow = (255, 100, 0)
|
||||
green = (0, 255, 0)
|
||||
blue = (0, 0, 255)
|
||||
indigo = (100, 0, 90)
|
||||
violet = (200, 0, 100)
|
||||
colors_rgb = [red, orange, yellow, green, blue, indigo, violet]
|
||||
|
||||
# same colors as normaln rgb, just 0 added at the end
|
||||
colors_rgbw = [color+tuple([0]) for color in colors_rgb]
|
||||
colors_rgbw.append((0, 0, 0, 255))
|
||||
|
||||
# uncomment colors_rgbw if you have RGBW strip
|
||||
colors = colors_rgb
|
||||
# colors = colors_rgbw
|
||||
|
||||
|
||||
step = round(numpix / len(colors))
|
||||
current_pixel = 0
|
||||
strip.brightness(50)
|
||||
|
||||
for color1, color2 in zip(colors, colors[1:]):
|
||||
strip.set_pixel_line_gradient(current_pixel, current_pixel + step, color1, color2)
|
||||
current_pixel += step
|
||||
|
||||
strip.set_pixel_line_gradient(current_pixel, numpix - 1, violet, red)
|
||||
|
||||
while True:
|
||||
strip.rotate_right(1)
|
||||
time.sleep(0.042)
|
||||
strip.show()
|
|
@ -0,0 +1,61 @@
|
|||
import time
|
||||
import neopixel
|
||||
import random
|
||||
|
||||
numpix = 60 # Number of NeoPixels
|
||||
# Pin where NeoPixels are connected
|
||||
strip = neopixel.neopixel(numpix, 0, 0, "RGBW")
|
||||
|
||||
colors_rgb = [
|
||||
(232, 100, 255), # Purple
|
||||
(200, 200, 20), # Yellow
|
||||
(30, 200, 200), # Blue
|
||||
(150,50,10),
|
||||
(50,200,10),
|
||||
]
|
||||
|
||||
# same colors as normaln rgb, just 0 added at the end
|
||||
colors_rgbw = [color+tuple([0]) for color in colors_rgb]
|
||||
colors_rgbw.append((0, 0, 0, 255))
|
||||
|
||||
# uncomment colors_rgbw if you have RGBW strip
|
||||
# colors = colors_rgb
|
||||
colors = colors_rgbw
|
||||
|
||||
max_len=20
|
||||
min_len = 5
|
||||
#pixelnum, posn in flash, flash_len, direction
|
||||
flashing = []
|
||||
|
||||
num_flashes = 10
|
||||
|
||||
for i in range(num_flashes):
|
||||
pix = random.randint(0, numpix - 1)
|
||||
col = random.randint(1, len(colors) - 1)
|
||||
flash_len = random.randint(min_len, max_len)
|
||||
flashing.append([pix, colors[col], flash_len, 0, 1])
|
||||
|
||||
strip.fill((0,0,0))
|
||||
|
||||
while True:
|
||||
strip.show()
|
||||
for i in range(num_flashes):
|
||||
|
||||
pix = flashing[i][0]
|
||||
brightness = (flashing[i][3]/flashing[i][2])
|
||||
colr = (int(flashing[i][1][0]*brightness),
|
||||
int(flashing[i][1][1]*brightness),
|
||||
int(flashing[i][1][2]*brightness))
|
||||
strip.set_pixel(pix, colr)
|
||||
|
||||
if flashing[i][2] == flashing[i][3]:
|
||||
flashing[i][4] = -1
|
||||
if flashing[i][3] == 0 and flashing[i][4] == -1:
|
||||
pix = random.randint(0, numpix - 1)
|
||||
col = random.randint(0, len(colors) - 1)
|
||||
flash_len = random.randint(min_len, max_len)
|
||||
flashing[i] = [pix, colors[col], flash_len, 0, 1]
|
||||
flashing[i][3] = flashing[i][3] + flashing[i][4]
|
||||
time.sleep(0.005)
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
import time
|
||||
from neopixel import neopixel
|
||||
|
||||
numpix = 60
|
||||
strip = neopixel(numpix, 0, 0, "RGBW")
|
||||
|
||||
red = (255, 0, 0)
|
||||
orange = (255, 165, 0)
|
||||
yellow = (255, 150, 0)
|
||||
green = (0, 255, 0)
|
||||
blue = (0, 0, 255)
|
||||
indigo = (75, 0, 130)
|
||||
violet = (138, 43, 226)
|
||||
colors_rgb = (red, orange, yellow, green, blue, indigo, violet)
|
||||
|
||||
# same colors as normaln rgb, just 0 added at the end
|
||||
colors_rgbw = [color+tuple([0]) for color in colors_rgb]
|
||||
colors_rgbw.append((0, 0, 0, 255))
|
||||
|
||||
# uncomment colors_rgbw if you have RGBW strip
|
||||
# colors = colors_rgb
|
||||
colors = colors_rgbw
|
||||
|
||||
strip.brightness(42)
|
||||
|
||||
while True:
|
||||
for color in colors:
|
||||
for i in range(numpix):
|
||||
strip.set_pixel(i, color)
|
||||
time.sleep(0.01)
|
||||
strip.show()
|
Ładowanie…
Reference in New Issue