Skip to content

Commit

Permalink
Add deinit to match core CircuitPython classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Sep 6, 2017
1 parent 89edb79 commit 89bc683
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,19 @@ def __init__(self, pin, n, bpp=3, brightness=1.0, auto_write=True):
self.brightness = brightness
self.auto_write = auto_write

def __enter__(self):
return self

def __exit__(self, exception_type, exception_value, traceback):
# Blank out the neopixels.
def deinit(self):
"""Blank out the NeoPixels and release the pin."""
for i in range(len(self.buf)):
self.buf[i] = 0
neopixel_write(self.pin, self.buf)
self.pin.deinit()

def __enter__(self):
return self

def __exit__(self, exception_type, exception_value, traceback):
self.deinit()

def __repr__(self):
return "[" + ", ".join([str(x) for x in self]) + "]"

Expand Down

0 comments on commit 89bc683

Please sign in to comment.