Skip to content

Commit

Permalink
DM: add brightness to seesaw neopix
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm1278 committed Sep 27, 2018
1 parent a2c3896 commit e3e3021
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions adafruit_seesaw/neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import ustruct as struct
from micropython import const

__version__ = "0.0.0-auto.0"
__version__ = "1.2.3"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"

_NEOPIXEL_BASE = const(0x0E)
Expand Down Expand Up @@ -57,22 +57,25 @@ def __init__(self, seesaw, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pi
self._bpp = bpp
self.auto_write = auto_write
self._n = n
self._brightness = brightness
self._brightness = min(max(brightness, 0.0), 1.0)
self._pixel_order = GRBW if pixel_order is None else pixel_order

cmd = bytearray([pin])
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_PIN, cmd)
cmd = struct.pack(">H", n*self._bpp)
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF_LENGTH, cmd)


@property
def brightness(self):
pass
"""Overall brightness of the pixel"""
return self._brightness

@brightness.setter
def brightness(self, value):
pass
def brightness(self, brightness):
# pylint: disable=attribute-defined-outside-init
self._brightness = min(max(brightness, 0.0), 1.0)
if self.auto_write:
self.show()

def deinit(self):
pass
Expand Down Expand Up @@ -102,6 +105,13 @@ def __setitem__(self, key, color):
g = 0
b = 0

if self.brightness < 0.99:
r = int(r * self.brightness)
g = int(g * self.brightness)
b = int(b * self.brightness)
if self._bpp == 4:
w = int(w * self.brightness)

# Store colors in correct slots
cmd[2 + self._pixel_order[0]] = r
cmd[2 + self._pixel_order[1]] = g
Expand Down

0 comments on commit e3e3021

Please sign in to comment.