Skip to content

Commit 9bccee7

Browse files
committed
Added RPi-specific example
1 parent 8b1124c commit 9bccee7

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

examples/rpi_neopixel_simpletest.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Simple test for NeoPixels on Raspberry Pi
2+
import time
3+
import board
4+
import neopixel
5+
6+
7+
# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18
8+
pixel_pin = board.D18
9+
10+
# The number of NeoPixels
11+
num_pixels = 30
12+
13+
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
14+
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
15+
ORDER = neopixel.GRB
16+
17+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.2, auto_write=False,
18+
pixel_order=ORDER)
19+
20+
21+
def wheel(pos):
22+
# Input a value 0 to 255 to get a color value.
23+
# The colours are a transition r - g - b - back to r.
24+
if pos < 0 or pos > 255:
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:
31+
pos -= 85
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)
41+
42+
43+
def rainbow_cycle(wait):
44+
for j in range(255):
45+
for i in range(num_pixels):
46+
pixel_index = (i * 256 // num_pixels) + j
47+
pixels[i] = wheel(pixel_index & 255)
48+
pixels.show()
49+
time.sleep(wait)
50+
51+
52+
while True:
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))
57+
pixels.show()
58+
time.sleep(1)
59+
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))
64+
pixels.show()
65+
time.sleep(1)
66+
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))
71+
pixels.show()
72+
time.sleep(1)
73+
74+
rainbow_cycle(0.001) # rainbow cycle with 1ms delay per step

0 commit comments

Comments
 (0)