Skip to content

Commit c7b1bc5

Browse files
committed
Removed tuple function, updated wheel
1 parent 2e7ab09 commit c7b1bc5

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

examples/neopixel_simpletest.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@
1414
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
1515
ORDER = neopixel.GRB
1616

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,
1818
pixel_order=ORDER)
1919

2020

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-
2721
def wheel(pos):
2822
# Input a value 0 to 255 to get a color value.
2923
# The colours are a transition r - g - b - back to r.
3024
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:
3531
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)
3941

4042

4143
def rainbow_cycle(wait):
@@ -48,15 +50,24 @@ def rainbow_cycle(wait):
4850

4951

5052
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))
5257
pixels.show()
5358
time.sleep(1)
5459

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))
5664
pixels.show()
5765
time.sleep(1)
5866

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))
6071
pixels.show()
6172
time.sleep(1)
6273

0 commit comments

Comments
 (0)