14
14
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
15
15
ORDER = neopixel .GRB
16
16
17
- pixels = neopixel .NeoPixel (pixel_pin , num_pixels , brightness = 0.3 , auto_write = False ,
17
+ pixels = neopixel .NeoPixel (pixel_pin , num_pixels , brightness = 0.2 , auto_write = False ,
18
18
pixel_order = ORDER )
19
19
20
20
21
- def format_tuple (r , g , b ):
22
- if ORDER == neopixel .RGB or ORDER == neopixel .GRB :
23
- return r , g , b
24
- return r , g , b , 0
25
-
26
-
27
21
def wheel (pos ):
28
22
# Input a value 0 to 255 to get a color value.
29
23
# The colours are a transition r - g - b - back to r.
30
24
if pos < 0 or pos > 255 :
31
- return format_tuple (0 , 0 , 0 )
32
- if pos < 85 :
33
- return format_tuple (int (pos * 3 ), int (255 - (pos * 3 )), 0 )
34
- if pos < 170 :
25
+ r = g = b = 0
26
+ elif pos < 85 :
27
+ r = int (pos * 3 )
28
+ g = int (255 - pos * 3 )
29
+ b = 0
30
+ elif pos < 170 :
35
31
pos -= 85
36
- return format_tuple (int (255 - pos * 3 ), 0 , int (pos * 3 ))
37
- pos -= 170
38
- return format_tuple (0 , int (pos * 3 ), int (255 - pos * 3 ))
32
+ r = int (255 - pos * 3 )
33
+ g = 0
34
+ b = int (pos * 3 )
35
+ else :
36
+ pos -= 170
37
+ r = 0
38
+ g = int (pos * 3 )
39
+ b = int (255 - pos * 3 )
40
+ return (r , g , b ) if ORDER == neopixel .RGB or ORDER == neopixel .GRB else (r , g , b , 0 )
39
41
40
42
41
43
def rainbow_cycle (wait ):
@@ -48,15 +50,24 @@ def rainbow_cycle(wait):
48
50
49
51
50
52
while True :
51
- pixels .fill (format_tuple (255 , 0 , 0 ))
53
+ # Comment this line out if you have RGBW/GRBW NeoPixels
54
+ pixels .fill ((255 , 0 , 0 ))
55
+ # Uncomment this line if you have RGBW/GRBW NeoPixels
56
+ # pixels.fill((255, 0, 0, 0))
52
57
pixels .show ()
53
58
time .sleep (1 )
54
59
55
- pixels .fill (format_tuple (0 , 255 , 0 ))
60
+ # Comment this line out if you have RGBW/GRBW NeoPixels
61
+ pixels .fill ((0 , 255 , 0 ))
62
+ # Uncomment this line if you have RGBW/GRBW NeoPixels
63
+ # pixels.fill((0, 255, 0, 0))
56
64
pixels .show ()
57
65
time .sleep (1 )
58
66
59
- pixels .fill (format_tuple (0 , 0 , 255 ))
67
+ # Comment this line out if you have RGBW/GRBW NeoPixels
68
+ pixels .fill ((0 , 0 , 255 ))
69
+ # Uncomment this line if you have RGBW/GRBW NeoPixels
70
+ # pixels.fill((0, 0, 255, 0))
60
71
pixels .show ()
61
72
time .sleep (1 )
62
73
0 commit comments