Skip to content

Commit 701cb11

Browse files
committed
Refactor to cover all math errors
1 parent fa7437c commit 701cb11

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

adafruit_is31fl3731/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def autoplay(self, delay=0, loops=0, frames=0):
190190
self._register(_CONFIG_BANK, _AUTOPLAY2_REGISTER, delay % 64)
191191
self._mode(_AUTOPLAY_MODE | self._frame)
192192

193-
def fade(self, fade_in=None, fade_out=None, pause=26):
193+
def fade(self, fade_in=None, fade_out=None, pause=0):
194194
"""
195195
Start and stop the fade feature. If both fade_in and fade_out are None (the
196196
default), the breath feature is used for fading. if fade_in is None, then
@@ -207,9 +207,13 @@ def fade(self, fade_in=None, fade_out=None, pause=26):
207207
fade_in = fade_out
208208
elif fade_out is None:
209209
fade_out = fade_in
210-
fade_in = int(math.log(fade_in / 26, 2))
211-
fade_out = int(math.log(fade_out / 26, 2))
212-
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))
213217
if not 0 <= fade_in <= 7:
214218
raise ValueError("Fade in out of range")
215219
if not 0 <= fade_out <= 7:

examples/is31fl3731_ledshim_fade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2023 E. A. Graham, Jr.
22
# SPDX-License-Identifier: MIT
33

44
import time

0 commit comments

Comments
 (0)