Skip to content

Commit 3d79874

Browse files
authored
Allow negative index with direct channel write
allow adressing a channel from the rear, e.g. tlc5947[-1] = 2048 # set last available channel to 50% intensity
1 parent dd8e40c commit 3d79874

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

adafruit_tlc5947.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def __getitem__(self, key):
245245
"""Retrieve the 12-bit PWM value for the specified channel (0-max).
246246
max depends on the number of boards.
247247
"""
248+
if key < 0: # allow reverse adressing with negative index
249+
key = key + _CHANNELS * self._n
248250
assert 0 <= key < _CHANNELS * self._n
249251
return self._get_gs_value(key)
250252

@@ -255,6 +257,8 @@ def __setitem__(self, key, val):
255257
immediately be updated too, otherwise you must call write to update
256258
the chip with the new PWM state.
257259
"""
260+
if key < 0: # allow reverse adressing with negative index
261+
key = key + _CHANNELS * self._n
258262
assert 0 <= key < _CHANNELS * self._n
259263
assert 0 <= val <= 4095
260264
self._set_gs_value(key, val)

0 commit comments

Comments
 (0)