Skip to content

Commit fdd65a2

Browse files
committed
Cosmetic fixes, updated rainbow_cycle
1 parent 4b9563d commit fdd65a2

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

examples/neopixel_simpletest.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
# CircuitPython demo - NeoPixel
2-
31
import time
42
import board
53
import neopixel
64

75

8-
# On CircuitPlayground Express -> Board.NEOPIXEL
9-
# Otherwise choose an open pin connected to the Data In of the NeoPixel strip,
10-
# such as board.D1
11-
# pylint: disable=no-member
12-
pixpin = board.NEOPIXEL
6+
# On CircuitPlayground Express, and boards with built in status NeoPixel -> board.NEOPIXEL
7+
# Otherwise choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D1
8+
pixel_pin = board.NEOPIXEL
139

14-
# The number of pixels in the strip
15-
numpix = 10
10+
# The number of NeoPixels
11+
num_pixels = 10
1612

17-
# number of colors in each pixel, =3 for RGB, =4 for RGB plus white
13+
# The number of colors in each pixel: 3 for RGB, 4 for RGBW (RGB plus white)
1814
BPP = 3
1915

20-
strip = neopixel.NeoPixel(pixpin, numpix, bpp=BPP, brightness=0.3, auto_write=False)
16+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, bpp=BPP, brightness=0.3, auto_write=False)
17+
2118

2219
def format_tuple(r, g, b):
2320
if BPP == 3:
24-
return (r, g, b)
25-
return (r, g, b, 0)
21+
return r, g, b
22+
return r, g, b, 0
23+
2624

2725
def wheel(pos):
2826
# Input a value 0 to 255 to get a color value.
2927
# The colours are a transition r - g - b - back to r.
30-
if (pos < 0) or (pos > 255):
28+
if pos < 0 or pos > 255:
3129
return format_tuple(0, 0, 0)
3230
if pos < 85:
3331
return format_tuple(int(pos * 3), int(255 - (pos*3)), 0)
@@ -37,25 +35,27 @@ def wheel(pos):
3735
pos -= 170
3836
return format_tuple(0, int(pos*3), int(255 - pos*3))
3937

38+
4039
def rainbow_cycle(wait):
4140
for j in range(255):
42-
for i in range(strip.n):
43-
idx = int((i * 256 / len(strip)) + j)
44-
strip[i] = wheel(idx & 255)
45-
strip.show()
41+
for i in range(num_pixels):
42+
pixel_index = (i * 256 // num_pixels) + j
43+
pixels[i] = wheel(pixel_index & 255)
44+
pixels.show()
4645
time.sleep(wait)
4746

47+
4848
while True:
49-
strip.fill(format_tuple(255, 0, 0))
50-
strip.show()
49+
pixels.fill(format_tuple(255, 0, 0))
50+
pixels.show()
5151
time.sleep(1)
5252

53-
strip.fill(format_tuple(0, 255, 0))
54-
strip.show()
53+
pixels.fill(format_tuple(0, 255, 0))
54+
pixels.show()
5555
time.sleep(1)
5656

57-
strip.fill(format_tuple(0, 0, 255))
58-
strip.show()
57+
pixels.fill(format_tuple(0, 0, 255))
58+
pixels.show()
5959
time.sleep(1)
6060

61-
rainbow_cycle(0.001) # rainbowcycle with 1ms delay per step
61+
rainbow_cycle(0.001) # rainbow cycle with 1ms delay per step

0 commit comments

Comments
 (0)