Skip to content

Commit 13bf88f

Browse files
committed
Add example for daisy chaining
1 parent 448a306 commit 13bf88f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

examples/pixels.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,31 @@
4343

4444
# Night Rider animation
4545

46+
def set_glowing_led(index, r, g, b, brightness):
47+
"""
48+
Set the color of the LED at the given index with its
49+
neighboring LEDs slightly dimmed to create a glowing effect.
50+
"""
51+
pixels.clear_all()
52+
pixels.set_rgb(index, r, g, b, brightness)
53+
54+
if index > 0:
55+
pixels.set_rgb(index - 1, r, g, b, brightness // 8) # LED to the left
56+
if index < 7:
57+
pixels.set_rgb(index + 1, r, g, b, brightness // 8) # LED to the right
58+
59+
pixels.show()
60+
4661
for j in range(0, 3):
4762
for i in range(0, 8):
48-
pixels.clear_all()
49-
pixels.set_rgb(i, 255, 0, 0, 100)
50-
pixels.show()
63+
set_glowing_led(i, 255, 0, 0, 100)
5164
sleep(0.05)
5265

5366
for i in range(7, -1, -1):
54-
pixels.clear_all()
55-
pixels.set_rgb(i, 255, 0, 0, 100)
56-
pixels.show()
67+
set_glowing_led(i, 255, 0, 0, 100)
5768
sleep(0.05)
5869

5970
# Turn off all LEDs
60-
pixels.clear_all()
61-
pixels.show()
71+
# Daisy chain the show() method to send the data to the LEDs
72+
# This works for all the methods that modify the LEDs' appearance.
73+
pixels.clear_all().show()

0 commit comments

Comments
 (0)