43
43
44
44
# Night Rider animation
45
45
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
+
46
61
for j in range (0 , 3 ):
47
62
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 )
51
64
sleep (0.05 )
52
65
53
66
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 )
57
68
sleep (0.05 )
58
69
59
70
# 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