diff --git a/README.rst b/README.rst index d4743e4..d4f919c 100644 --- a/README.rst +++ b/README.rst @@ -26,6 +26,7 @@ These drivers depends on: * `Seesaw `_ * `HT16K33 `_ * `DotStar `_ +* `NeoPixel `_ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading diff --git a/adafruit_featherwing/dotstar_featherwing.py b/adafruit_featherwing/dotstar_featherwing.py index e404320..6cf758c 100755 --- a/adafruit_featherwing/dotstar_featherwing.py +++ b/adafruit_featherwing/dotstar_featherwing.py @@ -33,8 +33,9 @@ import board import adafruit_dotstar as dotstar +from adafruit_featherwing.pixelmatrix import PixelMatrix -class DotStarFeatherWing: +class DotStarFeatherWing(PixelMatrix): """Class representing a `DotStar FeatherWing `_. @@ -45,320 +46,8 @@ def __init__(self, clock=board.D13, data=board.D11, brightness=0.2): :param pin data: The data pin for the featherwing :param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0 """ + super().__init__() self.rows = 6 self.columns = 12 - self._auto_write = True - self._dotstar = dotstar.DotStar(clock, data, self.rows * self.columns, - brightness=brightness, auto_write=False) - - def __setitem__(self, indices, value): - """ - indices can be one of three things: - x and y ints that are calculated to the DotStar index - a slice of DotStar indexes with a set of values that match the slice - a single int that specifies the DotStar index - value can be one of three things: - a (r,g,b) list/tuple - a (r,g,b, brightness) list/tuple - a single, longer int that contains RGB values, like 0xFFFFFF - brightness, if specified should be a float 0-1 - """ - self._dotstar[self._get_index(indices)] = value - self._update() - - def __getitem__(self, indices): - """ - indices can be one of three things: - x and y ints that are calculated to the DotStar index - a slice of DotStar indexes to retrieve - a single int that specifies the DotStar index - """ - return self._dotstar[self._get_index(indices)] - - def _get_index(self, indices): - """ - Figure out which DotStar to address based on what was passed in - """ - if isinstance(indices, int): - if not 0 <= indices < self.rows * self.columns: - raise ValueError('The index of {} is out of range'.format(indices)) - return indices - elif isinstance(indices, slice): - return indices - elif len(indices) == 2: - x, y = indices - if not 0 <= x < self.columns: - raise ValueError('The X value of {} is out of range'.format(x)) - if not 0 <= y < self.rows: - raise ValueError('The Y value of {} is out of range'.format(y)) - return y * self.columns + x - else: - raise ValueError('Index must be 1 or 2 number') - - def fill(self, color=0): - """ - Fills all of the DotStars with a color or unlit if empty. - - :param color: (Optional) The text or number to display (default=0) - :type color: list/tuple or int - - This example shows various ways of using the fill() function - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - dotstar.fill((255, 255, 255)) # Fill White - time.sleep(1) - dotstar.fill((255, 255, 255, 0.5)) # Fill White Half Brightness - time.sleep(1) - dotstar.fill(0xFF0000) # Fill Red - time.sleep(1) - dotstar.fill() # Clear all lit DotStars - - """ - self._dotstar.fill(color) - self._update() - - def show(self): - """ - Update the DotStars. This is only needed if auto_write is set to False - This can be very useful for more advanced graphics effects. - - This example changes the blink rate and prints out the current setting - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - dotstar.fill() # Clear any lit Dotstars - dotstar.auto_write = False - dotstar[0, 0] = (255, 255, 255) # Set White - time.sleep(1) - dotstar.show() # Update the DotStars - - """ - self._dotstar.show() - - def shift_right(self, rotate=False): - """ - Shift all pixels right - - :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False) - - This example shifts 2 pixels to the right - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - - # Draw Red and Green Pixels - dotstar[5, 3] = (255, 0, 0) - dotstar[6, 3] = (0, 255, 0) - - # Rotate it off the screen - for i in range(0, 11): - dotstar.shift_right(True) - time.sleep(.1) - - time.sleep(1) - # Shift it off the screen - for i in range(0, 11): - dotstar.shift_right() - time.sleep(.1) - - """ - for y in range(0, self.rows): - last_pixel = self._dotstar[(y + 1) * self.columns - 1] if rotate else 0 - for x in range(self.columns - 1, 0, -1): - self._dotstar[y * self.columns + x] = self._dotstar[y * self.columns + x - 1] - self._dotstar[y * self.columns] = last_pixel - self._update() - - def shift_left(self, rotate=False): - """ - Shift all pixels left - - :param rotate: (Optional) Rotate the shifted pixels to the right side (default=False) - - This example shifts 2 pixels to the left - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - - # Draw Red and Green Pixels - dotstar[5, 3] = (255, 0, 0) - dotstar[6, 3] = (0, 255, 0) - - # Rotate it off the screen - for i in range(0, 11): - dotstar.shift_left(True) - time.sleep(.1) - - time.sleep(1) - # Shift it off the screen - for i in range(0, 11): - dotstar.shift_left() - time.sleep(.1) - - """ - for y in range(0, self.rows): - last_pixel = self._dotstar[y * self.columns] if rotate else 0 - for x in range(0, self.columns - 1): - self._dotstar[y * self.columns + x] = self._dotstar[y * self.columns + x + 1] - self._dotstar[(y + 1) * self.columns - 1] = last_pixel - self._update() - - def shift_up(self, rotate=False): - """ - Shift all pixels up - - :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False) - - This example shifts 2 pixels up - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - - # Draw Red and Green Pixels - dotstar[5, 3] = (255, 0, 0) - dotstar[6, 3] = (0, 255, 0) - - # Rotate it off the screen - for i in range(0, 5): - dotstar.shift_up(True) - time.sleep(.1) - - time.sleep(1) - # Shift it off the screen - for i in range(0, 5): - dotstar.shift_up() - time.sleep(.1) - - """ - for x in range(0, self.columns): - last_pixel = self._dotstar[(self.rows - 1) * self.columns + x] if rotate else 0 - for y in range(self.rows - 1, 0, -1): - self._dotstar[y * self.columns + x] = self._dotstar[(y - 1) * self.columns + x] - self._dotstar[x] = last_pixel - self._update() - - def shift_down(self, rotate=False): - """ - Shift all pixels down - - :param rotate: (Optional) Rotate the shifted pixels to top (default=False) - - This example shifts 2 pixels down - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - - # Draw Red and Green Pixels - dotstar[5, 3] = (255, 0, 0) - dotstar[6, 3] = (0, 255, 0) - - # Rotate it off the screen - for i in range(0, 5): - dotstar.shift_down(True) - time.sleep(.1) - - time.sleep(1) - # Shift it off the screen - for i in range(0, 5): - dotstar.shift_down() - time.sleep(.1) - - """ - for x in range(0, self.columns): - last_pixel = self._dotstar[x] if rotate else 0 - for y in range(0, self.rows - 1): - self._dotstar[y * self.columns + x] = self._dotstar[(y + 1) * self.columns + x] - self._dotstar[(self.rows - 1) * self.columns + x] = last_pixel - self._update() - - def _update(self): - """ - Update the Display automatically if auto_write is set to True - """ - if self._auto_write: - self._dotstar.show() - - @property - def auto_write(self): - """ - Whether or not we are automatically updating - If set to false, be sure to call show() to update - - This lights DotStars with and without auto_write - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - dotstar.fill() # Clear any lit Dotstars - dotstar[0, 0] = (255, 255, 255) # Set White - time.sleep(1) - - dotstar.auto_write = False - dotstar[1, 0] = (255, 255, 255) # Set White - time.sleep(1) - dotstar.show() # Update the DotStars - - """ - return self._auto_write - - @auto_write.setter - def auto_write(self, write): - if isinstance(write, bool): - self._auto_write = write - - @property - def brightness(self): - """ - Overall brightness of the display - - This example changes the brightness - - .. code-block:: python - - import time - from adafruit_featherwing import dotstar_featherwing - - dotstar = dotstar_featherwing.DotStarFeatherWing() - dotstar.brightness = 0 - dotstar.fill(0xFFFFFF) - for i in range(0, 6): - dotstar.brightness = (i / 10) - time.sleep(.2) - - dotstar.brightness = 0.3 - - """ - return self._dotstar.brightness - - @brightness.setter - def brightness(self, brightness): - self._dotstar.brightness = min(max(brightness, 0.0), 1.0) - self._update() + self._matrix = dotstar.DotStar(clock, data, self.rows * self.columns, + brightness=brightness, auto_write=False) diff --git a/adafruit_featherwing/neopixel_featherwing.py b/adafruit_featherwing/neopixel_featherwing.py new file mode 100755 index 0000000..fb8da48 --- /dev/null +++ b/adafruit_featherwing/neopixel_featherwing.py @@ -0,0 +1,119 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_featherwing.neopixel_featherwing` +==================================================== + +Helper for using the `NeoPixel FeatherWing `_. + +* Author(s): Melissa LeBlanc-Williams +""" + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" + +import board +import neopixel +from adafruit_featherwing.pixelmatrix import PixelMatrix + +class NeoPixelFeatherWing(PixelMatrix): + """Class representing a `NeoPixel FeatherWing + `_. + + The feather uses pins D6 by default""" + def __init__(self, pixel_pin=board.D6, brightness=0.1): + """ + :param pin pixel_pin: The pin for the featherwing + :param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0 + """ + super().__init__() + self.rows = 4 + self.columns = 8 + self._matrix = neopixel.NeoPixel(pixel_pin, self.rows * self.columns, + brightness=brightness, auto_write=False, + pixel_order=neopixel.GRB) + + def shift_up(self, rotate=False): + """ + Shift all pixels up + + :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False) + + This example shifts 2 pixels up + + .. code-block:: python + + import time + from adafruit_featherwing import neopixel_featherwing + + neopixel = neopixel_featherwing.NeoPixelFeatherWing() + + # Draw Red and Green Pixels + neopixel[4, 1] = (255, 0, 0) + neopixel[5, 1] = (0, 255, 0) + + # Rotate it off the screen + for i in range(0, neopixel.rows - 1): + neopixel.shift_up(True) + time.sleep(.1) + + time.sleep(1) + # Shift it off the screen + for i in range(0, neopixel.rows - 1): + neopixel.shift_up() + time.sleep(.1) + + """ + super().shift_down(rotate) # Up and down are reversed + + def shift_down(self, rotate=False): + """ + Shift all pixels down. + + :param rotate: (Optional) Rotate the shifted pixels to top (default=False) + + This example shifts 2 pixels down + + .. code-block:: python + + import time + from adafruit_featherwing import neopixel_featherwing + + neopixel = neopixel_featherwing.NeoPixelFeatherWing() + + # Draw Red and Green Pixels + neopixel[4, 1] = (255, 0, 0) + neopixel[5, 1] = (0, 255, 0) + + # Rotate it off the screen + for i in range(0, neopixel.rows - 1): + neopixel.shift_down(True) + time.sleep(.1) + + time.sleep(1) + # Shift it off the screen + for i in range(0, neopixel.rows - 1): + neopixel.shift_down() + time.sleep(.1) + + """ + super().shift_up(rotate) # Up and down are reversed diff --git a/adafruit_featherwing/pixelmatrix.py b/adafruit_featherwing/pixelmatrix.py new file mode 100755 index 0000000..17e82b3 --- /dev/null +++ b/adafruit_featherwing/pixelmatrix.py @@ -0,0 +1,190 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_featherwing.pixelmatrix` +==================================================== + +Base Class for the `NeoPixel FeatherWing ` and +`DotStar FeatherWing `_. + +* Author(s): Melissa LeBlanc-Williams +""" + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" + +#pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation + +class PixelMatrix: + """Base Class for DotStar and NeoPixel FeatherWings + + The feather uses pins D13 and D11""" + def __init__(self): + self.rows = 0 + self.columns = 0 + self._matrix = None + self._auto_write = True + + def __setitem__(self, indices, value): + """ + indices can be one of three things: + x and y ints that are calculated to the DotStar index + a slice of DotStar indexes with a set of values that match the slice + a single int that specifies the DotStar index + value can be one of three things: + a (r,g,b) list/tuple + a (r,g,b, brightness) list/tuple + a single, longer int that contains RGB values, like 0xFFFFFF + brightness, if specified should be a float 0-1 + """ + self._matrix[self._get_index(indices)] = value + self._update() + + def __getitem__(self, indices): + """ + indices can be one of three things: + x and y ints that are calculated to the DotStar index + a slice of DotStar indexes to retrieve + a single int that specifies the DotStar index + """ + return self._matrix[self._get_index(indices)] + + def _get_index(self, indices): + """ + Figure out which DotStar to address based on what was passed in + """ + if isinstance(indices, int): + if not 0 <= indices < self.rows * self.columns: + raise ValueError('The index of {} is out of range'.format(indices)) + return indices + elif isinstance(indices, slice): + return indices + elif len(indices) == 2: + x, y = indices + if not 0 <= x < self.columns: + raise ValueError('The X value of {} is out of range'.format(x)) + if not 0 <= y < self.rows: + raise ValueError('The Y value of {} is out of range'.format(y)) + return y * self.columns + x + else: + raise ValueError('Index must be 1 or 2 number') + + def _update(self): + """ + Update the Display automatically if auto_write is set to True + """ + if self._auto_write: + self._matrix.show() + + def fill(self, color=0): + """ + Fills all of the Pixels with a color or unlit if empty. + + :param color: (Optional) The text or number to display (default=0) + :type color: list/tuple or int + """ + self._matrix.fill(color) + self._update() + + def show(self): + """ + Update the Pixels. This is only needed if auto_write is set to False + This can be very useful for more advanced graphics effects. + """ + self._matrix.show() + + def shift_right(self, rotate=False): + """ + Shift all pixels right + + :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False) + """ + for y in range(0, self.rows): + last_pixel = self._matrix[(y + 1) * self.columns - 1] if rotate else 0 + for x in range(self.columns - 1, 0, -1): + self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x - 1] + self._matrix[y * self.columns] = last_pixel + self._update() + + def shift_left(self, rotate=False): + """ + Shift all pixels left + + :param rotate: (Optional) Rotate the shifted pixels to the right side (default=False) + """ + for y in range(0, self.rows): + last_pixel = self._matrix[y * self.columns] if rotate else 0 + for x in range(0, self.columns - 1): + self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x + 1] + self._matrix[(y + 1) * self.columns - 1] = last_pixel + self._update() + + def shift_up(self, rotate=False): + """ + Shift all pixels up + + :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False) + """ + for x in range(0, self.columns): + last_pixel = self._matrix[(self.rows - 1) * self.columns + x] if rotate else 0 + for y in range(self.rows - 1, 0, -1): + self._matrix[y * self.columns + x] = self._matrix[(y - 1) * self.columns + x] + self._matrix[x] = last_pixel + self._update() + + def shift_down(self, rotate=False): + """ + Shift all pixels down + + :param rotate: (Optional) Rotate the shifted pixels to top (default=False) + """ + for x in range(0, self.columns): + last_pixel = self._matrix[x] if rotate else 0 + for y in range(0, self.rows - 1): + self._matrix[y * self.columns + x] = self._matrix[(y + 1) * self.columns + x] + self._matrix[(self.rows - 1) * self.columns + x] = last_pixel + self._update() + + @property + def auto_write(self): + """ + Whether or not we are automatically updating + If set to false, be sure to call show() to update + """ + return self._auto_write + + @auto_write.setter + def auto_write(self, write): + if isinstance(write, bool): + self._auto_write = write + + @property + def brightness(self): + """ + Overall brightness of the display + """ + return self._matrix.brightness + + @brightness.setter + def brightness(self, brightness): + self._matrix.brightness = min(max(brightness, 0.0), 1.0) + self._update() diff --git a/docs/api.rst b/docs/api.rst index 5cd9014..1c1e449 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -13,3 +13,5 @@ .. automodule:: adafruit_featherwing.dotstar_featherwing :members: +.. automodule:: adafruit_featherwing.neopixel_featherwing + :members: diff --git a/docs/examples.rst b/docs/examples.rst index a5e5ea1..757d8e4 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -19,9 +19,17 @@ Ensure your device works with this simple test. :caption: examples/featherwing_dotstar_simpletest.py :linenos: -.. literalinclude:: ../examples/featherwing_dotstar_palettetest.py - :caption: examples/featherwing_dotstar_palettetest.py +.. literalinclude:: ../examples/featherwing_neopixel_simpletest.py + :caption: examples/featherwing_neopixel_simpletest.py :linenos: +Other tests +------------ +.. literalinclude:: ../examples/featherwing_dotstar_palette_example.py + :caption: examples/featherwing_dotstar_palette_example.py + :linenos: +.. literalinclude:: ../examples/featherwing_neopixel_palette_example.py + :caption: examples/featherwing_neopixel_palette_example.py + :linenos: diff --git a/examples/featherwing_dotstar_palettetest.py b/examples/featherwing_dotstar_palette_example.py similarity index 95% rename from examples/featherwing_dotstar_palettetest.py rename to examples/featherwing_dotstar_palette_example.py index d13891b..e35c540 100644 --- a/examples/featherwing_dotstar_palettetest.py +++ b/examples/featherwing_dotstar_palette_example.py @@ -41,7 +41,7 @@ def rotate(degrees): dotstar.auto_write = False while True: for color in range(0, 360, 10): - for index in range(0, 72): + for index in range(0, dotstar.rows * dotstar.columns): palette_index = pixels[index] + color if palette_index >= 360: palette_index -= 360 diff --git a/examples/featherwing_dotstar_simpletest.py b/examples/featherwing_dotstar_simpletest.py index f301770..fb35dd2 100755 --- a/examples/featherwing_dotstar_simpletest.py +++ b/examples/featherwing_dotstar_simpletest.py @@ -1,5 +1,5 @@ """ -This example changes the screen different colors +This plays various animations and then draws random pixels at random locations """ diff --git a/examples/featherwing_neopixel_palette_example.py b/examples/featherwing_neopixel_palette_example.py new file mode 100644 index 0000000..a98a844 --- /dev/null +++ b/examples/featherwing_neopixel_palette_example.py @@ -0,0 +1,51 @@ +""" +This creates a palette of colors, draws a pattern and +rotates through the palette creating a moving rainbow. +""" + +from math import sqrt, cos, sin, radians +from adafruit_featherwing import neopixel_featherwing + +neopixel = neopixel_featherwing.NeoPixelFeatherWing() + +# Remap the calculated rotation to 0 - 255 +def remap(vector): + return int(((255 * vector + 85) * 0.75) + 0.5) + +# Calculate the Hue rotation starting with Red as 0 degrees +def rotate(degrees): + cosA = cos(radians(degrees)) + sinA = sin(radians(degrees)) + red = cosA + (1.0 - cosA) / 3.0 + green = 1./3. * (1.0 - cosA) + sqrt(1./3.) * sinA + blue = 1./3. * (1.0 - cosA) - sqrt(1./3.) * sinA + return (remap(red), remap(green), remap(blue)) + +palette = [] +pixels = [] + +# Generate a rainbow palette +for degree in range(0, 360): + color = rotate(degree) + palette.append(color[0] << 16 | color[1] << 8 | color[2]) + +# Create the Pattern +for y in range(0, neopixel.rows): + for x in range(0, neopixel.columns): + pixels.append(x * 30 + y * -30) + +# Clear the screen +neopixel.fill() + +# Start the Animation +neopixel.auto_write = False +while True: + for color in range(0, 360, 10): + for index in range(0, neopixel.rows * neopixel.columns): + palette_index = pixels[index] + color + if palette_index >= 360: + palette_index -= 360 + elif palette_index < 0: + palette_index += 360 + neopixel[index] = palette[palette_index] + neopixel.show() diff --git a/examples/featherwing_neopixel_simpletest.py b/examples/featherwing_neopixel_simpletest.py new file mode 100644 index 0000000..17c062b --- /dev/null +++ b/examples/featherwing_neopixel_simpletest.py @@ -0,0 +1,64 @@ +""" +This example plays various animations +and then draws random pixels at random locations +""" + +from time import sleep +import random +from adafruit_featherwing import neopixel_featherwing + +neopixel = neopixel_featherwing.NeoPixelFeatherWing() + +# HELPERS +# a random color 0 -> 224 +def random_color(): + return random.randrange(0, 8) * 32 + +# Fill screen with random colors at random brightnesses +for i in range(0, 5): + neopixel.fill((random_color(), random_color(), random_color())) + neopixel.brightness = random.randrange(2, 10) / 10 + sleep(.2) + +# Set display to 30% brightness +neopixel.brightness = 0.3 + +# Create a gradiant drawing each pixel +for x in range(0, neopixel.columns): + for y in range(neopixel.rows - 1, -1, -1): + neopixel[x, y] = (y * 63, 255, y * 63) + +#Rotate everything left 36 frames +for i in range(0, 36): + neopixel.shift_down(True) + sleep(0.1) + +# Draw dual gradiant and then update +#neopixel.auto_write = False +for y in range(0, neopixel.rows): + for x in range(0, 4): + neopixel[x, y] = (y * 16 + 32, x * 8, 0) + for x in range(4, 8): + neopixel[x, y] = ((4 - y) * 16 + 32, (8 - x) * 8, 0) +neopixel.show() + +# Rotate everything left 36 frames +for i in range(0, 36): + neopixel.shift_left(True) + neopixel.shift_up(True) + neopixel.show() + sleep(0.1) +neopixel.auto_write = True + +# Shift pixels without rotating for an animated screen wipe +for i in range(0, neopixel.rows): + neopixel.shift_down() + sleep(0.4) + +# Show pixels in random locations of random color +# Bottom left corner is (0,0) +while True: + x = random.randrange(0, neopixel.columns) + y = random.randrange(0, neopixel.rows) + neopixel[x, y] = (random_color(), random_color(), random_color()) + sleep(.1) diff --git a/requirements.txt b/requirements.txt index 1cbf8f4..32c8ec6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ adafruit-circuitpython-ina219 adafruit-circuitpython-seesaw adafruit-circuitpython-ht16k33 adafruit-circuitpython-dotstar +adafruit-circuitpython-neopixel diff --git a/setup.py b/setup.py index 95aa788..90b67ee 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice', 'adafruit-circuitpython-register', 'adafruit-circuitpython-ina219', 'adafruit-circuitpython-seesaw', 'adafruit-circuitpython-ht16k33', - 'adafruit-circuitpython-dotstar'], + 'adafruit-circuitpython-dotstar', 'adafruit-circuitpython-neopixel'], # Choose your license license='MIT',