-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.py
71 lines (59 loc) · 2 KB
/
order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
import board
import time
import neopixel
import sys
import math
import numpy as np
# LED strip configuration:
LED_COUNT = 5 # 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 = 5 # DMA channel to use for generating signal (try 5)
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
# LED_STRIP = ws.WS2811_STRIP_GRB # Strip type and colour ordering
pixels = neopixel.NeoPixel(board.D18, 5, pixel_order=neopixel.RGB)
palettes = {
"rainbow": [
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1, 1, 1],
[0, .33, .67],
],
"warmish": [
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1.0, 0.7, 0.4],
[0.0, 0.15, 0.2],
],
"red": [
[0.8, 0.5, 0.4],
[0.2, 0.4, 0.2],
[2, 1, 1],
[0, .25, .25],
],
"redblue": [
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1, 1, 1],
[0, 0.1, 0.2],
]
}
def color(t, pallet="redblue"):
a, b, c, d = palettes[pallet]
a, b, c, d = np.array(a), np.array(b), np.array(c), np.array(d)
c = a + b * np.cos(2 * math.pi * (c * t + d))
return (c * 256) % 256
i = 0
while True:
for p in range(LED_COUNT):
i += 1
t = (i * 0.001) % 1
r, g, b = color(t)
if (i % 100 == 0):
print(t, r, g, b)
pixels[p] = (r, g, b)
time.sleep(0.01)