Skip to content

Commit 5433ba3

Browse files
authored
Merge pull request #53 from EAGrahamJr/fade_52
Return from fade on "None"
2 parents 97eb72a + 701cb11 commit 5433ba3

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ _build
3838
# Virtual environment-specific files
3939
.env
4040
.venv
41+
venv
4142

4243
# MacOS-specific files
4344
*.DS_Store

adafruit_is31fl3731/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
Base library.
1212
13-
* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude
13+
* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude, E. A. Graham Jr.
1414
1515
Implementation Notes
1616
--------------------
@@ -202,13 +202,18 @@ def fade(self, fade_in=None, fade_out=None, pause=0):
202202
"""
203203
if fade_in is None and fade_out is None:
204204
self._register(_CONFIG_BANK, _BREATH2_REGISTER, 0)
205-
elif fade_in is None:
205+
return
206+
if fade_in is None:
206207
fade_in = fade_out
207208
elif fade_out is None:
208209
fade_out = fade_in
209-
fade_in = int(math.log(fade_in / 26, 2))
210-
fade_out = int(math.log(fade_out / 26, 2))
211-
pause = int(math.log(pause / 26, 2))
210+
211+
if fade_in != 0:
212+
fade_in = int(math.log(fade_in / 26, 2))
213+
if fade_out != 0:
214+
fade_out = int(math.log(fade_out / 26, 2))
215+
if pause != 0:
216+
pause = int(math.log(pause / 26, 2))
212217
if not 0 <= fade_in <= 7:
213218
raise ValueError("Fade in out of range")
214219
if not 0 <= fade_out <= 7:

examples/is31fl3731_ledshim_fade.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-FileCopyrightText: 2023 E. A. Graham, Jr.
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import board
6+
import busio
7+
from adafruit_is31fl3731.led_shim import LedShim as Display
8+
9+
i2c = busio.I2C(board.SCL, board.SDA)
10+
11+
# initial display if you are using Pimoroni LED SHIM
12+
display = Display(i2c)
13+
14+
y = 1
15+
for x in range(28):
16+
display.pixel(x, y, 255)
17+
18+
display.fade(fade_in=104, pause=250)
19+
20+
try:
21+
while True:
22+
time.sleep(10)
23+
except KeyboardInterrupt:
24+
display.sleep(True)

0 commit comments

Comments
 (0)