Skip to content

Fix NeoPixel brightness bug #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
Jun 7, 2021
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
13 changes: 12 additions & 1 deletion adafruit_seesaw/neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_PIN, cmd)
cmd = struct.pack(">H", n * self._bpp)
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF_LENGTH, cmd)
self._pre_brightness_color = [None] * n

@property
def brightness(self):
Expand All @@ -90,8 +91,16 @@ def brightness(self):
def brightness(self, brightness):
# pylint: disable=attribute-defined-outside-init
self._brightness = min(max(brightness, 0.0), 1.0)
if self.auto_write:

# Suppress auto_write while updating brightness.
current_auto_write = self.auto_write
self.auto_write = False
for i in range(self._n):
if self._pre_brightness_color[i] is not None:
self[i] = self._pre_brightness_color[i]
if current_auto_write:
self.show()
self.auto_write = current_auto_write

def deinit(self):
pass
Expand All @@ -114,6 +123,8 @@ def __setitem__(self, key, color):
else:
r, g, b, w = color

self._pre_brightness_color[key] = color

# If all components are the same and we have a white pixel then use it
# instead of the individual components.
if self._bpp == 4 and r == g == b and w == 0:
Expand Down