20
20
https://github.com/adafruit/circuitpython/releases
21
21
"""
22
22
try :
23
- from typing import Union
23
+ from typing import Union , Optional , Type
24
+ from types import TracebackType
25
+ from microcontroller import Pin
26
+ from adafruit_pca9685 import PWMChannel
27
+ from circuitpython_typing .led import ColorBasedColorUnion
24
28
except ImportError :
25
29
pass
26
30
32
36
33
37
class RGBLED :
34
38
"""
35
- Creates a RGBLED object given three physical pins or PWMOut objects.
39
+ Create an RGBLED object given three physical pins or PWMOut objects.
36
40
37
- Example for setting a RGB LED using a RGB Tuple (Red, Green, Blue):
41
+ Example for setting an RGB LED using an RGB Tuple (Red, Green, Blue):
38
42
39
43
.. code-block:: python
40
44
@@ -49,7 +53,7 @@ class RGBLED:
49
53
led = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
50
54
led.color = (255, 0, 0)
51
55
52
- Example for setting a RGB LED using a 24-bit integer (hex syntax):
56
+ Example for setting an RGB LED using a 24-bit integer (hex syntax):
53
57
54
58
.. code-block:: python
55
59
@@ -60,11 +64,11 @@ class RGBLED:
60
64
GREEN_LED = board.D6
61
65
BLUE_LED = board.D7
62
66
63
- # Create a RGB LED object
67
+ # Create an RGB LED object
64
68
led = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
65
69
led.color = 0x100000
66
70
67
- Example for setting a RGB LED using a ContextManager:
71
+ Example for setting an RGB LED using a ContextManager:
68
72
69
73
.. code-block:: python
70
74
@@ -115,7 +119,12 @@ def __init__(
115
119
def __enter__ (self ) -> "RGBLED" :
116
120
return self
117
121
118
- def __exit__ (self , exception_type , exception_value , traceback ) -> None :
122
+ def __exit__ (
123
+ self ,
124
+ exception_type : Optional [Type [type ]],
125
+ exception_value : Optional [BaseException ],
126
+ traceback : Optional [TracebackType ],
127
+ ) -> None :
119
128
self .deinit ()
120
129
121
130
def deinit (self ) -> None :
@@ -125,11 +134,15 @@ def deinit(self) -> None:
125
134
self ._current_color = (0 , 0 , 0 )
126
135
127
136
@property
128
- def color (self ) -> Union [ int , tuple ] :
137
+ def color (self ) -> ColorBasedColorUnion :
129
138
"""
130
139
Sets the RGB LED to a desired color.
131
- :param Union[int, tuple] value: RGB LED desired value - can be a RGB tuple of values
132
- 0 - 255 or a 24-bit integer. e.g. (255, 64, 35) and 0xff4023 are equivalent.
140
+
141
+ :param ColorBasedColorUnion value: RGB LED desired value - can be a RGB
142
+ tuple of values 0 - 255 or a 24-bit integer. e.g. (255, 64, 35) and 0xff4023
143
+ are equivalent.
144
+
145
+ :returns Union[int, Tuple[int, int, int]]: The current LED color setting.
133
146
134
147
:raises ValueError: If the input is an int > 0xffffff or is a tuple that does not
135
148
contain 3 integers of 0 - 255.
@@ -138,7 +151,7 @@ def color(self) -> Union[int, tuple]:
138
151
return self ._current_color
139
152
140
153
@color .setter
141
- def color (self , value : Union [ int , tuple ] ):
154
+ def color (self , value : ColorBasedColorUnion ):
142
155
if isinstance (value , int ):
143
156
try :
144
157
# Check that integer is <= 0xffffff and create an iterable.
0 commit comments