Skip to content

Commit

Permalink
Refactor to cover all math errors
Browse files Browse the repository at this point in the history
  • Loading branch information
EAGrahamJr committed Feb 22, 2023
1 parent fa7437c commit 701cb11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions adafruit_is31fl3731/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def autoplay(self, delay=0, loops=0, frames=0):
self._register(_CONFIG_BANK, _AUTOPLAY2_REGISTER, delay % 64)
self._mode(_AUTOPLAY_MODE | self._frame)

def fade(self, fade_in=None, fade_out=None, pause=26):
def fade(self, fade_in=None, fade_out=None, pause=0):
"""
Start and stop the fade feature. If both fade_in and fade_out are None (the
default), the breath feature is used for fading. if fade_in is None, then
Expand All @@ -207,9 +207,13 @@ def fade(self, fade_in=None, fade_out=None, pause=26):
fade_in = fade_out
elif fade_out is None:
fade_out = fade_in
fade_in = int(math.log(fade_in / 26, 2))
fade_out = int(math.log(fade_out / 26, 2))
pause = int(math.log(pause / 26, 2))

if fade_in != 0:
fade_in = int(math.log(fade_in / 26, 2))
if fade_out != 0:
fade_out = int(math.log(fade_out / 26, 2))
if pause != 0:
pause = int(math.log(pause / 26, 2))
if not 0 <= fade_in <= 7:
raise ValueError("Fade in out of range")
if not 0 <= fade_out <= 7:
Expand Down
2 changes: 1 addition & 1 deletion examples/is31fl3731_ledshim_fade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-FileCopyrightText: 2023 E. A. Graham, Jr.
# SPDX-License-Identifier: MIT

import time
Expand Down

0 comments on commit 701cb11

Please sign in to comment.