Skip to content

Commit

Permalink
Allow NEOPIXEL_POWER* init outside of NeoPixel lib
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
anecdata authored Aug 11, 2021
1 parent b2f21e6 commit 65eefcc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 65eefcc

Please sign in to comment.