Skip to content

Commit 7cf785e

Browse files
authored
Merge pull request #6 from caternuson/fixes
Some fixes
2 parents 8375614 + d7d2fd9 commit 7cf785e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

examples/neopixel_spi_simpletest.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
"""Eventual example for NeoPixel SPI"""
1+
import time
2+
import board
3+
import neopixel_spi as neopixel
4+
5+
NUM_PIXELS = 12
6+
PIXEL_ORDER = neopixel.GRB
7+
COLORS = (0xFF0000, 0x00FF00, 0x0000FF)
8+
DELAY = 0.1
9+
10+
spi = board.SPI()
11+
12+
pixels = neopixel.NeoPixel_SPI(spi,
13+
NUM_PIXELS,
14+
pixel_order=PIXEL_ORDER,
15+
auto_write=False)
16+
17+
while True:
18+
for color in COLORS:
19+
for i in range(NUM_PIXELS):
20+
pixels[i] = color
21+
pixels.show()
22+
time.sleep(DELAY)
23+
pixels.fill(0)

neopixel_spi.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
4444
"""
4545

46+
# The following creates a mock neopixel_write module to allow importing
47+
# the CircuitPython NeoPixel module without actually providing neopixel_write.
48+
#pylint: disable=wrong-import-position, exec-used
49+
import sys
50+
from types import ModuleType
51+
MOCK_MODULE = ModuleType('mock_neopixel_write')
52+
exec('def neopixel_write(): pass', MOCK_MODULE.__dict__)
53+
sys.modules['neopixel_write'] = MOCK_MODULE
54+
#pylint: enable=wrong-import-position, exec-used
55+
4656
from neopixel import NeoPixel
4757

4858
__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
96106
except AttributeError:
97107
# use nominal
98108
freq = self.FREQ
99-
self.RESET = bytes([0]*round(freq*self.TRST))
109+
self.RESET = bytes([0]*round(freq * self.TRST / 8))
100110
self.n = n
101111
if pixel_order is None:
102112
self.order = GRBW

0 commit comments

Comments
 (0)