Skip to content

Commit f179783

Browse files
add brightness property; update examples; format with black
1 parent b7822a7 commit f179783

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

adafruit_neotrellis/multitrellis.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1-
# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2021 Dean Miller for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
44

55
"""
6-
Interface for connecting together multiple NeoTrellis boards.
7-
"""
6+
``adafruit_multitrellis``
7+
====================================================
8+
9+
A CircuitPython driver class for interfacing clusters of 4x4 NeoTrellis with
10+
elastomer buttons and NeoPixel RGB LEDs.
11+
12+
* Author(s): Dean Miller, JG for CedarGroveMakerStudios
13+
14+
Implementation Notes
15+
--------------------
16+
17+
**Hardware:**
818
9-
# imports
19+
* 'NeoTrellis RGB Driver PCB for 4x4 Keypad, PID: 3954
20+
<https://www.adafruit.com/product/3954>'
1021
11-
__version__ = "1.1.8"
22+
**Software and Dependencies:**
23+
24+
* Adafruit CircuitPython firmware for the supported boards:
25+
https://github.com/adafruit/circuitpython/releases
26+
27+
* Adafruit Seesaw CircuitPython library
28+
https://github.com/adafruit/Adafruit_CircuitPython_seesaw/releases
29+
"""
30+
31+
__version__ = "0.0.0-auto.0"
1232
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_neotrellis.git"
1333

34+
1435
from time import sleep
1536
from micropython import const
1637
from adafruit_seesaw.keypad import KeyEvent
@@ -81,11 +102,14 @@ def sync(self):
81102

82103
@property
83104
def brightness(self):
105+
"""The NeoPixel brightness level of all clustered NeoTrellis boards."""
84106
return self.brightness
85107

86108
@brightness.setter
87109
def brightness(self, new_brightness):
110+
"""Select a NeoPixel brightness level for all all clustered boards. A
111+
valid brightness value is in the range of 0.0 to 1.0."""
88112
self._brightness = new_brightness
89113
for _r in range(self._rows):
90-
for _c in range (self._cols):
114+
for _c in range(self._cols):
91115
self._trelli[_r][_c].brightness = self._brightness

adafruit_neotrellis/neotrellis.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2021 Dean Miller for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
44

55
"""
66
``adafruit_neotrellis``
77
====================================================
88
9-
4x4 elastomer buttons and RGB LEDs
9+
A CircuitPython driver class for the 4x4 NeoTrellis with elastomer buttons and
10+
NeoPixel RGB LEDs.
1011
1112
* Author(s): Dean Miller, JG for CedarGroveMakerStudios
1213
@@ -15,6 +16,9 @@
1516
1617
**Hardware:**
1718
19+
* 'NeoTrellis RGB Driver PCB for 4x4 Keypad, PID: 3954
20+
<https://www.adafruit.com/product/3954>'
21+
1822
**Software and Dependencies:**
1923
2024
* Adafruit CircuitPython firmware for the supported boards:
@@ -24,9 +28,7 @@
2428
https://github.com/adafruit/Adafruit_CircuitPython_seesaw/releases
2529
"""
2630

27-
# imports
28-
29-
__version__ = "1.1.8"
31+
__version__ = "0.0.0-auto.0"
3032
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_neotrellis.git"
3133

3234
from time import sleep
@@ -54,14 +56,26 @@ def _seesaw_key(xval):
5456

5557

5658
class NeoTrellis(Keypad):
57-
"""Driver for the Adafruit NeoTrellis."""
58-
59-
def __init__(self, i2c_bus, interrupt=False, addr=_NEO_TRELLIS_ADDR, drdy=None, brightness=1.0):
59+
"""Driver for the Adafruit 4x4 NeoTrellis."""
60+
61+
def __init__(
62+
self,
63+
i2c_bus,
64+
interrupt=False,
65+
addr=_NEO_TRELLIS_ADDR,
66+
drdy=None,
67+
brightness=1.0,
68+
):
6069
super().__init__(i2c_bus, addr, drdy)
6170
self.interrupt_enabled = interrupt
6271
self._brightness = brightness
6372
self.callbacks = [None] * _NEO_TRELLIS_NUM_KEYS
64-
self.pixels = NeoPixel(self, _NEO_TRELLIS_NEOPIX_PIN, _NEO_TRELLIS_NUM_KEYS, brightness=self._brightness)
73+
self.pixels = NeoPixel(
74+
self,
75+
_NEO_TRELLIS_NEOPIX_PIN,
76+
_NEO_TRELLIS_NUM_KEYS,
77+
brightness=self._brightness,
78+
)
6579

6680
def activate_key(self, key, edge, enable=True):
6781
"""Activate or deactivate a key on the trellis. Key is the key number from
@@ -89,9 +103,12 @@ def sync(self):
89103

90104
@property
91105
def brightness(self):
106+
"""The NeoPixel brightness level of the board."""
92107
return self._brightness
93108

94109
@brightness.setter
95110
def brightness(self, new_brightness):
111+
"""Select a NeoPixel brightness level for the board. A valid brightness
112+
value is in the range of 0.0 to 1.0."""
96113
self._brightness = new_brightness
97114
self.pixels.brightness = self._brightness

examples/neotrellis_multitrellis_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
trelli = [
2323
[NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)],
2424
[NeoTrellis(i2c_bus, False, addr=0x30), NeoTrellis(i2c_bus, False, addr=0x31)],
25-
]
25+
]
2626

2727
trellis = MultiTrellis(trelli)
2828

0 commit comments

Comments
 (0)