|
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,51 @@ 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 | + Pass through to underlying NeoPixel object. |
| 89 | + For use when auto_write == False |
| 90 | +
|
| 91 | + Shows the new colors on the pixels themselves if they haven't already |
| 92 | + been autowritten. |
| 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. trellis.pixels.fill() should really be used here |
| 106 | + since all pixels are the same, but this is just for the sake of example. |
| 107 | +
|
| 108 | + .. code-block:: python |
| 109 | +
|
| 110 | + import adafruit_trellism4 |
| 111 | +
|
| 112 | + trellis = adafruit_trellism4.TrellisM4Express() |
| 113 | +
|
| 114 | + trellis.pixels.auto_write = False |
| 115 | +
|
| 116 | + for x in range(trellis.pixels.width): |
| 117 | + for y in range(trellis.pixels.height): |
| 118 | + trellis.pixels[x, y] = (0, 255, 0) |
| 119 | +
|
| 120 | + trellis.pixels.show() # must call show() when auto_write == False |
| 121 | +
|
| 122 | + trellis.pixels.auto_write = True |
| 123 | + """ |
| 124 | + return self._neopixel.auto_write |
| 125 | + |
| 126 | + @auto_write.setter |
| 127 | + def auto_write(self, val): |
| 128 | + self._neopixel.auto_write = val |
| 129 | + |
87 | 130 | @property
|
88 | 131 | def brightness(self):
|
89 | 132 | """
|
@@ -125,7 +168,6 @@ def fill(self, color):
|
125 | 168 |
|
126 | 169 | """
|
127 | 170 | self._neopixel.fill(color)
|
128 |
| - self._neopixel.show() |
129 | 171 |
|
130 | 172 | @property
|
131 | 173 | def width(self):
|
|
0 commit comments