Skip to content

Commit 0e08aa0

Browse files
authored
Merge pull request #1795 from adafruit/PyLeap-NeoPixel-demo
Updated PyLeap Demo Code
2 parents bc68747 + c5fe168 commit 0e08aa0

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

PyLeap_NeoPixel_demo/code.py

100644100755
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@
33
import neopixel
44

55
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.2, auto_write=False)
6+
rainbow_cycle_demo = 1
7+
8+
def colorwheel(pos):
9+
if pos < 0 or pos > 255:
10+
return (0, 0, 0)
11+
if pos < 85:
12+
return (255 - pos * 3, pos * 3, 0)
13+
if pos < 170:
14+
pos -= 85
15+
return (0, 255 - pos * 3, pos * 3)
16+
pos -= 170
17+
return (pos * 3, 0, 255 - pos * 3)
18+
19+
def rainbow_cycle(wait):
20+
for j in range(255):
21+
for i in range(10):
22+
rc_index = (i * 256 // 10) + j * 5
23+
pixels[i] = colorwheel(rc_index & 255)
24+
pixels.show()
25+
time.sleep(wait)
626

727
while True:
8-
for j in range(255):
9-
for i in range(len(pixels)):
10-
rc_index = (i * 256 // len(pixels)) + j
11-
pixels[i] = neopixel._pixelbuf.wheel(rc_index)
12-
pixels.show()
28+
if rainbow_cycle_demo:
29+
rainbow_cycle(0.05)

0 commit comments

Comments
 (0)