Skip to content

Allow setting color with an int from rainbowio #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions adafruit_character_lcd/character_lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ def color(self):

The following example turns the LCD red and displays, "Hello, world!".

The property returns a list, but can be set as an int in the format ``0xRRGGBB``,
as output by `rainbowio.colorwheel` for example.

.. code-block:: python

import time
Expand All @@ -691,6 +694,14 @@ def color(self):

@color.setter
def color(self, color):
if isinstance(color, int):
if color >> 24:
raise ValueError("Integer color value must be positive and 24 bits max")
# NOTE: convert to 0-100
r = (color >> 16) / 2.55
g = ((color >> 8) & 0xFF) / 2.55
b = (color & 0xFF) / 2.55
color = [r, g, b]
self._color = color
for number, pin in enumerate(self.rgb_led):
if hasattr(pin, "duty_cycle"):
Expand Down