diff --git a/examples/neopixel_spi_simpletest.py b/examples/neopixel_spi_simpletest.py index 1755e10..3757406 100644 --- a/examples/neopixel_spi_simpletest.py +++ b/examples/neopixel_spi_simpletest.py @@ -1 +1,23 @@ -"""Eventual example for NeoPixel SPI""" +import time +import board +import neopixel_spi as neopixel + +NUM_PIXELS = 12 +PIXEL_ORDER = neopixel.GRB +COLORS = (0xFF0000, 0x00FF00, 0x0000FF) +DELAY = 0.1 + +spi = board.SPI() + +pixels = neopixel.NeoPixel_SPI(spi, + NUM_PIXELS, + pixel_order=PIXEL_ORDER, + auto_write=False) + +while True: + for color in COLORS: + for i in range(NUM_PIXELS): + pixels[i] = color + pixels.show() + time.sleep(DELAY) + pixels.fill(0) diff --git a/neopixel_spi.py b/neopixel_spi.py index e01e2e2..21c94bf 100644 --- a/neopixel_spi.py +++ b/neopixel_spi.py @@ -43,6 +43,16 @@ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ +# The following creates a mock neopixel_write module to allow importing +# the CircuitPython NeoPixel module without actually providing neopixel_write. +#pylint: disable=wrong-import-position, exec-used +import sys +from types import ModuleType +MOCK_MODULE = ModuleType('mock_neopixel_write') +exec('def neopixel_write(): pass', MOCK_MODULE.__dict__) +sys.modules['neopixel_write'] = MOCK_MODULE +#pylint: enable=wrong-import-position, exec-used + from neopixel import NeoPixel __version__ = "0.0.0-auto.0" @@ -96,7 +106,7 @@ def __init__(self, spi, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_orde except AttributeError: # use nominal freq = self.FREQ - self.RESET = bytes([0]*round(freq*self.TRST)) + self.RESET = bytes([0]*round(freq * self.TRST / 8)) self.n = n if pixel_order is None: self.order = GRBW