Skip to content

Automatically turn on NEOPIXEL_POWER when using the NEOPIXEL pin #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"""

# pylint: disable=ungrouped-imports
import sys
import board
import digitalio
from neopixel_write import neopixel_write

Expand Down Expand Up @@ -101,10 +103,22 @@ def __init__(
):
if not pixel_order:
pixel_order = GRB if bpp == 3 else GRBW
else:
if isinstance(pixel_order, tuple):
order_list = [RGBW[order] for order in pixel_order]
pixel_order = "".join(order_list)
elif isinstance(pixel_order, tuple):
order_list = [RGBW[order] for order in pixel_order]
pixel_order = "".join(order_list)

self._power = None
if (
sys.implementation.version[0] >= 7
and getattr(board, "NEOPIXEL", None) == pin
):
power = getattr(board, "NEOPIXEL_POWER_INVERTED", None)
polarity = power is None
if not power:
power = getattr(board, "NEOPIXEL_POWER", None)
if power:
self._power = digitalio.DigitalInOut(power)
self._power.switch_to_output(value=polarity)

super().__init__(
n, brightness=brightness, byteorder=pixel_order, auto_write=auto_write
Expand All @@ -118,6 +132,8 @@ def deinit(self):
self.fill(0)
self.show()
self.pin.deinit()
if self._power:
self._power.deinit()

def __enter__(self):
return self
Expand Down