From 65eefcc2925ab3638128d9567237c91cb5145b1f Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 11 Aug 2021 15:11:38 -0500 Subject: [PATCH] Allow NEOPIXEL_POWER* init outside of NeoPixel lib Ignore exception when trying to set up `NEOPIXEL_POWER`* pin, since user may have set that up already for controlling power independently of this library. Tested on `Adafruit CircuitPython 7.0.0-alpha.5-187-g1e53cf40a on 2021-08-11; Adafruit MagTag with ESP32S2`; code snippet: ```py import digitalio, neopixel # NeoPixels & light sensor aux_power_io = digitalio.DigitalInOut(board.NEOPIXEL_POWER_INVERTED) aux_power_io.direction = Direction.OUTPUT aux_power_io.value = False # active low status_light = neopixel.NeoPixel(board.NEOPIXEL, 4, brightness=0.05, pixel_order=neopixel.GRB) ``` --- neopixel.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/neopixel.py b/neopixel.py index 6af8d95..9b62818 100644 --- a/neopixel.py +++ b/neopixel.py @@ -120,8 +120,11 @@ def __init__( if not power: power = getattr(board, "NEOPIXEL_POWER", None) if power: - self._power = digitalio.DigitalInOut(power) - self._power.switch_to_output(value=polarity) + try: + self._power = digitalio.DigitalInOut(power) + self._power.switch_to_output(value=polarity) + except ValueError: + pass super().__init__( n, brightness=brightness, byteorder=pixel_order, auto_write=auto_write