File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -673,6 +673,9 @@ def color(self):
673
673
674
674
The following example turns the LCD red and displays, "Hello, world!".
675
675
676
+ The property returns a list, but can be set as an int in the format ``0xRRGGBB``,
677
+ as output by `rainbowio.colorwheel` for example.
678
+
676
679
.. code-block:: python
677
680
678
681
import time
@@ -691,6 +694,14 @@ def color(self):
691
694
692
695
@color .setter
693
696
def color (self , color ):
697
+ if isinstance (color , int ):
698
+ if color >> 24 :
699
+ raise ValueError ("Integer color value must be positive and 24 bits max" )
700
+ # NOTE: convert to 0-100
701
+ r = (color >> 16 ) / 2.55
702
+ g = ((color >> 8 ) & 0xFF ) / 2.55
703
+ b = (color & 0xFF ) / 2.55
704
+ color = [r , g , b ]
694
705
self ._color = color
695
706
for number , pin in enumerate (self .rgb_led ):
696
707
if hasattr (pin , "duty_cycle" ):
You can’t perform that action at this time.
0 commit comments