Skip to content

Commit 89bc683

Browse files
committed
Add deinit to match core CircuitPython classes.
1 parent 89edb79 commit 89bc683

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

neopixel.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,19 @@ def __init__(self, pin, n, bpp=3, brightness=1.0, auto_write=True):
8080
self.brightness = brightness
8181
self.auto_write = auto_write
8282

83-
def __enter__(self):
84-
return self
85-
86-
def __exit__(self, exception_type, exception_value, traceback):
87-
# Blank out the neopixels.
83+
def deinit(self):
84+
"""Blank out the NeoPixels and release the pin."""
8885
for i in range(len(self.buf)):
8986
self.buf[i] = 0
9087
neopixel_write(self.pin, self.buf)
9188
self.pin.deinit()
9289

90+
def __enter__(self):
91+
return self
92+
93+
def __exit__(self, exception_type, exception_value, traceback):
94+
self.deinit()
95+
9396
def __repr__(self):
9497
return "[" + ", ".join([str(x) for x in self]) + "]"
9598

0 commit comments

Comments
 (0)