|
54 | 54 | class _NeoPixelArray:
|
55 | 55 | """Creates a NeoPixel array for use in the ``TrellisM4Express`` class."""
|
56 | 56 | def __init__(self, pin, *, width, height, rotation=0):
|
57 |
| - self._neopixel = neopixel.NeoPixel(pin, width * height, auto_write=False) |
| 57 | + self._neopixel = neopixel.NeoPixel(pin, width * height, auto_write=True) |
58 | 58 | if rotation % 90 != 0:
|
59 | 59 | raise ValueError("Only 90 degree rotations supported")
|
60 | 60 | self._rotation = rotation % 360
|
@@ -82,8 +82,50 @@ def __setitem__(self, index, value):
|
82 | 82 | raise IndexError("Pixel assignment outside available coordinates.")
|
83 | 83 |
|
84 | 84 | self._neopixel[offset] = value
|
| 85 | + |
| 86 | + def show(self): |
| 87 | + """ |
| 88 | + Shows the new colors on the pixels themselves if they haven't already |
| 89 | + been autowritten. |
| 90 | +
|
| 91 | + Use when ``auto_write`` is set to ``False``. |
| 92 | +
|
| 93 | + The colors may or may not be showing after this function returns because |
| 94 | + it may be done asynchronously. |
| 95 | + """ |
85 | 96 | self._neopixel.show()
|
86 | 97 |
|
| 98 | + @property |
| 99 | + def auto_write(self): |
| 100 | + """ |
| 101 | + True if the neopixels should immediately change when set. If False, |
| 102 | + ``show`` must be called explicitly. |
| 103 | +
|
| 104 | + This example disables ``auto_write``, sets every pixel, calls ``show()``, then |
| 105 | + re-enables ``auto-write``. |
| 106 | +
|
| 107 | + .. code-block:: python |
| 108 | +
|
| 109 | + import adafruit_trellism4 |
| 110 | +
|
| 111 | + trellis = adafruit_trellism4.TrellisM4Express() |
| 112 | +
|
| 113 | + trellis.pixels.auto_write = False |
| 114 | +
|
| 115 | + for x in range(trellis.pixels.width): |
| 116 | + for y in range(trellis.pixels.height): |
| 117 | + trellis.pixels[x, y] = (0, 255, 0) |
| 118 | +
|
| 119 | + trellis.pixels.show() # must call show() when auto_write == False |
| 120 | +
|
| 121 | + trellis.pixels.auto_write = True |
| 122 | + """ |
| 123 | + return self._neopixel.auto_write |
| 124 | + |
| 125 | + @auto_write.setter |
| 126 | + def auto_write(self, val): |
| 127 | + self._neopixel.auto_write = val |
| 128 | + |
87 | 129 | @property
|
88 | 130 | def brightness(self):
|
89 | 131 | """
|
@@ -125,7 +167,6 @@ def fill(self, color):
|
125 | 167 |
|
126 | 168 | """
|
127 | 169 | self._neopixel.fill(color)
|
128 |
| - self._neopixel.show() |
129 | 170 |
|
130 | 171 | @property
|
131 | 172 | def width(self):
|
|
0 commit comments