Skip to content

Commit

Permalink
Merge pull request #72 from jfurcean/fix-brightness
Browse files Browse the repository at this point in the history
Fix NeoPixel brightness bug
  • Loading branch information
kattni committed Jun 7, 2021
2 parents db8ed66 + 78a7a4c commit 5812855
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 5812855

Please sign in to comment.