Skip to content

Commit ec36b9b

Browse files
committed
different approach
1 parent 4040308 commit ec36b9b

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
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)

faux_write.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

neopixel_spi.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +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
4649
import sys
47-
sys.modules['neopixel_write'] = __import__('faux_write')
50+
from types import ModuleType
51+
mock_neopixel_write = ModuleType('mock_neopixel_write')
52+
exec('def neopixel_write(): pass', mock_neopixel_write.__dict__)
53+
sys.modules['neopixel_write'] = mock_neopixel_write
54+
#pylint: enable=wrong-import-position
55+
4856
from neopixel import NeoPixel
4957

5058
__version__ = "0.0.0-auto.0"
@@ -60,6 +68,12 @@
6068
GRBW = (1, 0, 2, 3)
6169
"""Green Red Blue White"""
6270

71+
def neopixel_write():
72+
"""This is a stub function to satisfy the base NeoPixel library.
73+
It should never be called.
74+
"""
75+
raise RuntimeError("Function should never be called.")
76+
6377
class NeoPixel_SPI(NeoPixel):
6478
"""
6579
A sequence of neopixels.

0 commit comments

Comments
 (0)