@@ -35,19 +35,63 @@ def _mapi(self, x, in_min, in_max, out_min, out_max) -> int:
35
35
return int (self ._map (x , in_min , in_max , out_min , out_max ))
36
36
37
37
def set_range_rgb (self , index_from , index_to , r , g , b , brightness = 100 ):
38
+ """
39
+ Sets the color of the LEDs in the given range to the given RGB values.
40
+
41
+ Parameters:
42
+ index_from (int): The starting index of the range.
43
+ index_to (int): The ending index (inclusive) of the range.
44
+ r (int): The red value of the color.
45
+ g (int): The green value of the color.
46
+ b (int): The blue value of the color.
47
+ brightness (int): The brightness of the LED. It should be a value between 0 and 100.
48
+ """
38
49
self .set_range_color (index_from , index_to , ModulinoColor (r , g , b ), brightness )
39
50
40
51
def set_range_color (self , index_from , index_to , color , brightness = 100 ):
52
+ """
53
+ Sets the color of the LEDs in the given range to the given color.
54
+
55
+ Parameters:
56
+ index_from (int): The starting index of the range.
57
+ index_to (int): The ending index (inclusive) of the range.
58
+ color (ModulinoColor): The color of the LEDs.
59
+ brightness (int): The brightness of the LED. It should be a value between 0 and 100.
60
+ """
41
61
for i in range (index_from , index_to + 1 ):
42
62
self .set_color (i , color , brightness )
43
63
44
64
def set_all_rgb (self , r , g , b , brightness = 100 ):
65
+ """
66
+ Sets the color of all the LEDs to the given RGB values.
67
+
68
+ Parameters:
69
+ r (int): The red value of the color.
70
+ g (int): The green value of the color.
71
+ b (int): The blue value of the color.
72
+ brightness (int): The brightness of the LED. It should be a value between 0 and 100.
73
+ """
45
74
self .set_all_color (ModulinoColor (r , g , b ), brightness )
46
75
47
76
def set_all_color (self , color , brightness = 100 ):
77
+ """
78
+ Sets the color of all the LEDs to the given color.
79
+
80
+ Parameters:
81
+ color (ModulinoColor): The color of the LEDs.
82
+ brightness (int): The brightness of the LED. It should be a value between 0 and 100.
83
+ """
48
84
self .set_range_color (0 , NUM_LEDS - 1 , color , brightness )
49
85
50
86
def set_color (self , idx , rgb : ModulinoColor , brightness = 100 ):
87
+ """
88
+ Sets the color of the given LED index to the given color.
89
+
90
+ Parameters:
91
+ idx (int): The index of the LED.
92
+ rgb (ModulinoColor): The color of the LED.
93
+ brightness (int): The brightness of the LED. It should be a value between 0 and 100.
94
+ """
51
95
if idx < 0 or idx >= NUM_LEDS :
52
96
raise ValueError (f"LED index out of range { idx } (Valid: 0..{ NUM_LEDS - 1 } )" )
53
97
@@ -57,17 +101,43 @@ def set_color(self, idx, rgb : ModulinoColor , brightness=100):
57
101
self .data [byte_index : byte_index + 4 ] = color_data_bytes .to_bytes (4 , 'little' )
58
102
59
103
def set_rgb (self , idx , r , g , b , brightness = 100 ):
104
+ """
105
+ Set the color of the given LED index to the given RGB values.
106
+
107
+ Parameters:
108
+ idx (int): The index of the LED.
109
+ r (int): The red value of the color.
110
+ g (int): The green value of the color.
111
+ b (int): The blue value of the color.
112
+ brightness (int): The brightness of the LED. It should be a value between 0 and 100.
113
+ """
60
114
self .set_color (idx , ModulinoColor (r , g , b ), brightness )
61
115
62
116
def clear (self , idx ):
117
+ """
118
+ Turns off the LED at the given index.
119
+
120
+ Parameters:
121
+ idx (int): The index of the LED.
122
+ """
63
123
self .set_color (idx , ModulinoColor (0 , 0 , 0 ), 0 )
64
124
65
125
def clear_range (self , start , end ):
66
126
for i in range (start , end ):
67
127
self .clear (i )
68
128
69
129
def clear_all (self ):
130
+ """
131
+ Turns all the LEDs off.
132
+
133
+ Parameters:
134
+ idx (int): The index of the LED
135
+ """
70
136
self .data = bytearray ([0xE0 ] * NUM_LEDS * 4 )
71
137
72
138
def show (self ):
139
+ """
140
+ Applies the changes to the LEDs. This function needs to be called after any changes to the LEDs.
141
+ Otherwise, the changes will not be visible.
142
+ """
73
143
self .write (self .data )
0 commit comments