diff --git a/.gitignore b/.gitignore index db3d538..546a827 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ _build # Virtual environment-specific files .env .venv +venv # MacOS-specific files *.DS_Store diff --git a/adafruit_is31fl3731/__init__.py b/adafruit_is31fl3731/__init__.py index c8cd30c..49290a4 100644 --- a/adafruit_is31fl3731/__init__.py +++ b/adafruit_is31fl3731/__init__.py @@ -10,7 +10,7 @@ Base library. -* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude +* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude, E. A. Graham Jr. Implementation Notes -------------------- @@ -202,13 +202,18 @@ def fade(self, fade_in=None, fade_out=None, pause=0): """ if fade_in is None and fade_out is None: self._register(_CONFIG_BANK, _BREATH2_REGISTER, 0) - elif fade_in is None: + return + if fade_in is None: 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: diff --git a/examples/is31fl3731_ledshim_fade.py b/examples/is31fl3731_ledshim_fade.py new file mode 100644 index 0000000..eb7ecda --- /dev/null +++ b/examples/is31fl3731_ledshim_fade.py @@ -0,0 +1,24 @@ +# SPDX-FileCopyrightText: 2023 E. A. Graham, Jr. +# SPDX-License-Identifier: MIT + +import time +import board +import busio +from adafruit_is31fl3731.led_shim import LedShim as Display + +i2c = busio.I2C(board.SCL, board.SDA) + +# initial display if you are using Pimoroni LED SHIM +display = Display(i2c) + +y = 1 +for x in range(28): + display.pixel(x, y, 255) + +display.fade(fade_in=104, pause=250) + +try: + while True: + time.sleep(10) +except KeyboardInterrupt: + display.sleep(True)