diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6977a9..3baf502 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Build CI on: [pull_request, push] @@ -38,20 +42,32 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, black, & Sphinx + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - - name: Check formatting - run: | - black --check --target-version=py35 . - - name: PyLint + - name: Pre-commit hooks run: | - pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) + pre-commit run --all-files - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Archive bundles + uses: actions/upload-artifact@v2 + with: + name: bundles + path: ${{ github.workspace }}/bundles/ - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Build Python package + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + pip install --upgrade setuptools wheel twine readme_renderer testresources + python setup.py sdist + python setup.py bdist_wheel --universal + twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18efb9c..6d0015a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Release Actions on: diff --git a/.gitignore b/.gitignore index c83f8b7..9647e71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + *.mpy .idea __pycache__ @@ -8,4 +12,4 @@ bundles *.DS_Store .eggs dist -**/*.egg-info \ No newline at end of file +**/*.egg-info diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..354c761 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/python/black + rev: 20.8b1 + hooks: + - id: black +- repo: https://github.com/fsfe/reuse-tool + rev: v0.12.1 + hooks: + - id: reuse +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/pycqa/pylint + rev: pylint-2.7.1 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + exclude: "^(docs/|examples/|setup.py$)" +- repo: local + hooks: + - id: pylint_examples + name: pylint (examples code) + description: Run pylint rules on "examples/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + language: system diff --git a/.pylintrc b/.pylintrc index d8f0ee8..9ed669e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + [MASTER] # A comma-separated list of package or module names from where C extensions may @@ -246,7 +250,7 @@ ignore-comments=yes ignore-docstrings=yes # Ignore imports when computing similarities. -ignore-imports=no +ignore-imports=yes # Minimum lines number of a similarity. min-similarity-lines=4 diff --git a/.readthedocs.yml b/.readthedocs.yml index f4243ad..ffa84c4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + python: version: 3 requirements_file: requirements.txt diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 134d510..8a55c07 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,9 @@ + + # Adafruit Community Code of Conduct ## Our Pledge @@ -43,7 +49,7 @@ Examples of unacceptable behavior by participants include: The goal of the standards and moderation guidelines outlined here is to build and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -74,9 +80,9 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Moderators by tagging @community moderators. You may -also send an open message from any channel, or a direct message to -@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +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 (including the next +paragraph) 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. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +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 +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. For more information, +please refer to diff --git a/README.rst b/README.rst index 61fa057..0fd4124 100644 --- a/README.rst +++ b/README.rst @@ -22,6 +22,7 @@ This driver supports the following hardware: * `Adafruit 16x8 CharliePlex LED Matrix Bonnets `_ * `Pimoroni 17x7 Scroll pHAT HD `_ * `Pimoroni 28x3 (r,g,b) Led Shim `_ +* `Pimoroni Keybow 2040 with 4x4 matrix of RGB LEDs `_ Dependencies @@ -66,11 +67,11 @@ Matrix: .. code:: python - import adafruit_is31fl3731 + from adafruit_is31fl3731.matrix import Matrix import board import busio with busio.I2C(board.SCL, board.SDA) as i2c: - display = adafruit_is31fl3731.Matrix(i2c) + display = Matrix(i2c) display.fill(127) @@ -78,11 +79,11 @@ Charlie Wing: .. code:: python - import adafruit_is31fl3731 + from adafruit_is31fl3731.charlie_wing import CharlieWing import board import busio with busio.I2C(board.SCL, board.SDA) as i2c: - display = adafruit_is31fl3731.CharlieWing(i2c) + display = CharlieWing(i2c) display.fill(127) # Turn off pixel 4,4, change its brightness and turn it back on diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731/__init__.py similarity index 69% rename from adafruit_is31fl3731.py rename to adafruit_is31fl3731/__init__.py index cf4b673..2d65f4e 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731/__init__.py @@ -1,24 +1,6 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries # -# Copyright (c) 2017 Tony DiCola -# -# 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. +# SPDX-License-Identifier: MIT """ `adafruit_is31fl3731` @@ -26,8 +8,9 @@ CircuitPython driver for the IS31FL3731 charlieplex IC. +Base library. -* Author(s): Tony DiCola, Melissa LeBlanc-Williams +* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude Implementation Notes -------------------- @@ -40,10 +23,29 @@ * `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings `_ +* `Adafruit 16x8 CharliePlex LED Matrix Bonnets + `_ + +* `Pimoroni 17x7 Scroll pHAT HD + `_ + +* `Pimoroni 28x3 (r,g,b) Led Shim + `_ + +* `Pimoroni LED SHIM + `_ + +* `Pimoroni Keybow 2040 + `_ + +* `Pimoroni 11x7 LED Matrix Breakout + `_ + **Software and Dependencies:** -* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards: +* Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases + """ # imports @@ -78,9 +80,10 @@ _COLOR_OFFSET = const(0x24) -class Matrix: +class IS31FL3731: """ - The Matrix class support the main function for driving the 16x9 matrix Display + The IS31FL3731 is an abstract class contain the main function related to this chip. + Each board needs to define width, height and pixel_addr. :param ~adafruit_bus_device.i2c_device i2c_device: the connected i2c bus i2c_device :param address: the device address; defaults to 0x74 @@ -93,7 +96,6 @@ def __init__(self, i2c, address=0x74): self.i2c = i2c self.address = address self._frame = None - self.reset() self._init() def _i2c_read_reg(self, reg, result): @@ -141,6 +143,8 @@ def _mode(self, mode=None): return self._register(_CONFIG_BANK, _MODE_REGISTER, mode) def _init(self): + self.sleep(True) + time.sleep(0.01) # 10 MS pause to reset. self._mode(_PICTURE_MODE) self.frame(0) for frame in range(8): @@ -148,6 +152,7 @@ def _init(self): for col in range(18): self._register(frame, _ENABLE_OFFSET + col, 0xFF) self.audio_sync(False) + self.sleep(False) def reset(self): """Kill the display for 10MS""" @@ -230,13 +235,11 @@ def frame(self, frame=None, show=True): return None def audio_sync(self, value=None): - """Set the audio sync feature register - """ + """Set the audio sync feature register""" return self._register(_CONFIG_BANK, _AUDIOSYNC_REGISTER, value) def audio_play(self, sample_rate, audio_gain=0, agc_enable=False, agc_fast=False): - """Controls the audio play feature - """ + """Controls the audio play feature""" if sample_rate == 0: self._mode(_PICTURE_MODE) return @@ -255,8 +258,7 @@ def audio_play(self, sample_rate, audio_gain=0, agc_enable=False, agc_fast=False self._mode(_AUDIOPLAY_MODE) def blink(self, rate=None): - """Updates the blink register - """ + """Updates the blink register""" # pylint: disable=no-else-return # This needs to be refactored when it can be tested if rate is None: @@ -296,10 +298,10 @@ def fill(self, color=None, blink=None, frame=None): for col in range(18): self._register(frame, _BLINK_OFFSET + col, data) + # This function must be replaced for each board @staticmethod def pixel_addr(x, y): - """Calulate the offset into the device array for x,y pixel - """ + """Calulate the offset into the device array for x,y pixel""" return x + y * 16 # pylint: disable-msg=too-many-arguments @@ -362,139 +364,3 @@ def image(self, img, blink=None, frame=None): for x in range(self.width): # yes this double loop is slow, for y in range(self.height): # but these displays are small! self.pixel(x, y, pixels[(x, y)], blink=blink, frame=frame) - - -class CharlieWing(Matrix): - """Supports the Charlieplexed feather wing - """ - - width = 15 - height = 7 - - @staticmethod - def pixel_addr(x, y): - """Calulate the offset into the device array for x,y pixel - """ - if x > 7: - x = 15 - x - y += 8 - else: - y = 7 - y - return x * 16 + y - - -class CharlieBonnet(Matrix): - """Supports the Charlieplexed bonnet""" - - width = 16 - height = 8 - - @staticmethod - def pixel_addr(x, y): - """Calulate the offset into the device array for x,y pixel""" - if x >= 8: - return (x - 6) * 16 - (y + 1) - return (x + 1) * 16 + (7 - y) - - -class ScrollPhatHD(Matrix): - """Supports the Scroll pHAT HD by Pimoroni""" - - width = 17 - height = 7 - - @staticmethod - def pixel_addr(x, y): - """Translate an x,y coordinate to a pixel index.""" - if x <= 8: - x = 8 - x - y = 6 - y - else: - x = x - 8 - y = y - 8 - return x * 16 + y - - -class LedShim(Matrix): - """Supports the LED SHIM by Pimoroni""" - - width = 28 - height = 3 - - def __init__(self, i2c, address=0x75): - super().__init__(i2c, address) - - # pylint: disable-msg=too-many-arguments - def pixelrgb(self, x, r, g, b, blink=None, frame=None): - """ - Blink or brightness for x-pixel - - :param x: horizontal pixel position - :param r: red brightness value 0->255 - :param g: green brightness value 0->255 - :param b: blue brightness value 0->255 - :param blink: True to blink - :param frame: the frame to set the pixel - """ - super().pixel(x, 0, r, blink, frame) - super().pixel(x, 1, g, blink, frame) - super().pixel(x, 2, b, blink, frame) - - # pylint: disable=inconsistent-return-statements - # pylint: disable=too-many-return-statements - # pylint: disable=too-many-branches - - @staticmethod - def pixel_addr(x, y): - """Translate an x,y coordinate to a pixel index.""" - if y == 0: - if x < 7: - return 118 - x - if x < 15: - return 141 - x - if x < 21: - return 106 + x - if x == 21: - return 15 - return x - 14 - - if y == 1: - if x < 2: - return 69 - x - if x < 7: - return 86 - x - if x < 12: - return 28 - x - if x < 14: - return 45 - x - if x == 14: - return 47 - if x == 15: - return 41 - if x < 21: - return x + 9 - if x == 21: - return 95 - if x < 26: - return x + 67 - return x + 50 - - if x == 0: - return 85 - if x < 7: - return 102 - x - if x < 11: - return 44 - x - if x < 14: - return 61 - x - if x == 14: - return 63 - if x < 17: - return 42 + x - if x < 21: - return x + 25 - if x == 21: - return 111 - if x < 27: - return x + 83 - return 93 diff --git a/adafruit_is31fl3731/charlie_bonnet.py b/adafruit_is31fl3731/charlie_bonnet.py new file mode 100644 index 0000000..5dad110 --- /dev/null +++ b/adafruit_is31fl3731/charlie_bonnet.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_is31fl3731.charlie_bonnet` +==================================================== + +CircuitPython driver for the IS31FL3731 charlieplex IC. + + +* Author(s): Tony DiCola, Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +* `Adafruit 16x8 CharliePlex LED Matrix Bonnets + `_ + + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +# imports +from . import IS31FL3731 + + +class CharlieBonnet(IS31FL3731): + """Supports the Charlieplexed bonnet""" + + width = 16 + height = 8 + + @staticmethod + def pixel_addr(x, y): + """Calulate the offset into the device array for x,y pixel""" + if x >= 8: + return (x - 6) * 16 - (y + 1) + return (x + 1) * 16 + (7 - y) diff --git a/adafruit_is31fl3731/charlie_wing.py b/adafruit_is31fl3731/charlie_wing.py new file mode 100644 index 0000000..79d9224 --- /dev/null +++ b/adafruit_is31fl3731/charlie_wing.py @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_is31fl3731.charlie_wing` +==================================================== + +CircuitPython driver for the IS31FL3731 charlieplex IC. + + +* Author(s): Tony DiCola, Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings + `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +# imports +from . import IS31FL3731 + + +class CharlieWing(IS31FL3731): + """Supports the Charlieplexed feather wing""" + + width = 15 + height = 7 + + @staticmethod + def pixel_addr(x, y): + """Calulate the offset into the device array for x,y pixel""" + if x > 7: + x = 15 - x + y += 8 + else: + y = 7 - y + return x * 16 + y diff --git a/adafruit_is31fl3731/keybow2040.py b/adafruit_is31fl3731/keybow2040.py new file mode 100644 index 0000000..d8946a9 --- /dev/null +++ b/adafruit_is31fl3731/keybow2040.py @@ -0,0 +1,86 @@ +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_is31fl3731.charlie_bonnet` +==================================================== + +CircuitPython driver for the IS31FL3731 charlieplex IC. + + +* Author(s): Tony DiCola, Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +* `Pimoroni Keybow 2040 + `_ + + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +# imports +from . import IS31FL3731 + + +class Keybow2040(IS31FL3731): + """Supports the Pimoroni Keybow 2040 with 4x4 matrix of RGB LEDs """ + + width = 16 + height = 3 + + # pylint: disable=too-many-arguments + + def pixelrgb(self, x, y, r, g, b, blink=None, frame=None): + """ + Blink or brightness for x, y-pixel + + :param x: horizontal pixel position + :param y: vertical pixel position + :param r: red brightness value 0->255 + :param g: green brightness value 0->255 + :param b: blue brightness value 0->255 + :param blink: True to blink + :param frame: the frame to set the pixel + """ + x = (4 * (3 - x)) + y + + super().pixel(x, 0, g, blink, frame) + super().pixel(x, 1, r, blink, frame) + super().pixel(x, 2, b, blink, frame) + + # pylint: disable=inconsistent-return-statements + # pylint: disable=too-many-return-statements + # pylint: disable=too-many-branches + + @staticmethod + def pixel_addr(x, y): + + lookup = [ + (120, 88, 104), # 0, 0 + (136, 40, 72), # 1, 0 + (112, 80, 96), # 2, 0 + (128, 32, 64), # 3, 0 + (121, 89, 105), # 0, 1 + (137, 41, 73), # 1, 1 + (113, 81, 97), # 2, 1 + (129, 33, 65), # 3, 1 + (122, 90, 106), # 0, 2 + (138, 25, 74), # 1, 2 + (114, 82, 98), # 2, 2 + (130, 17, 66), # 3, 2 + (123, 91, 107), # 0, 3 + (139, 26, 75), # 1, 3 + (115, 83, 99), # 2, 3 + (131, 18, 67), # 3, 3 + ] + + return lookup[x][y] diff --git a/adafruit_is31fl3731/led_shim.py b/adafruit_is31fl3731/led_shim.py new file mode 100644 index 0000000..fbba938 --- /dev/null +++ b/adafruit_is31fl3731/led_shim.py @@ -0,0 +1,115 @@ +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_is31fl3731.led_shim` +==================================================== + +CircuitPython driver for the IS31FL3731 charlieplex IC. + + +* Author: David Glaude + +Implementation Notes +-------------------- + +**Hardware:** + +* `Pimoroni 28 RGB Led Shim + `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +# imports +from . import IS31FL3731 + + +class LedShim(IS31FL3731): + """Supports the LED SHIM by Pimoroni""" + + width = 28 + height = 3 + + def __init__(self, i2c, address=0x75): + super().__init__(i2c, address) + + # pylint: disable-msg=too-many-arguments + def pixelrgb(self, x, r, g, b, blink=None, frame=None): + """ + Blink or brightness for x-pixel + + :param x: horizontal pixel position + :param r: red brightness value 0->255 + :param g: green brightness value 0->255 + :param b: blue brightness value 0->255 + :param blink: True to blink + :param frame: the frame to set the pixel + """ + super().pixel(x, 0, r, blink, frame) + super().pixel(x, 1, g, blink, frame) + super().pixel(x, 2, b, blink, frame) + + # pylint: disable=inconsistent-return-statements + # pylint: disable=too-many-return-statements + # pylint: disable=too-many-branches + + @staticmethod + def pixel_addr(x, y): + """Translate an x,y coordinate to a pixel index.""" + if y == 0: + if x < 7: + return 118 - x + if x < 15: + return 141 - x + if x < 21: + return 106 + x + if x == 21: + return 15 + return x - 14 + + if y == 1: + if x < 2: + return 69 - x + if x < 7: + return 86 - x + if x < 12: + return 28 - x + if x < 14: + return 45 - x + if x == 14: + return 47 + if x == 15: + return 41 + if x < 21: + return x + 9 + if x == 21: + return 95 + if x < 26: + return x + 67 + return x + 50 + + if x == 0: + return 85 + if x < 7: + return 102 - x + if x < 11: + return 44 - x + if x < 14: + return 61 - x + if x == 14: + return 63 + if x < 17: + return 42 + x + if x < 21: + return x + 25 + if x == 21: + return 111 + if x < 27: + return x + 83 + return 93 diff --git a/adafruit_is31fl3731/matrix.py b/adafruit_is31fl3731/matrix.py new file mode 100644 index 0000000..94a2c9e --- /dev/null +++ b/adafruit_is31fl3731/matrix.py @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_is31fl3731.matrix` +==================================================== + +CircuitPython driver for the IS31FL3731 charlieplex IC. + + +* Author(s): Tony DiCola, Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +* `Adafruit 16x9 Charlieplexed PWM LED Matrix Driver - IS31FL3731 + `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +# imports +from . import IS31FL3731 + + +class Matrix(IS31FL3731): + """Supports the Charlieplexed feather wing""" + + width = 16 + height = 9 + + @staticmethod + def pixel_addr(x, y): + """Calulate the offset into the device array for x,y pixel""" + return x + y * 16 diff --git a/adafruit_is31fl3731/matrix_11x7.py b/adafruit_is31fl3731/matrix_11x7.py new file mode 100644 index 0000000..741e3e0 --- /dev/null +++ b/adafruit_is31fl3731/matrix_11x7.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_is31fl3731.charlie_bonnet` +==================================================== + +CircuitPython driver for the IS31FL3731 charlieplex IC. + + +* Author(s): Tony DiCola, Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +* `Pimoroni 11x7 LED Matrix Breakout `_ + + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +# imports +from . import IS31FL3731 + + +class Matrix11x7(IS31FL3731): + """Supports the 11x7 LED Matrix Breakout by Pimoroni""" + + width = 11 + height = 7 + + def __init__(self, i2c, address=0x75): + super().__init__(i2c, address) + + @staticmethod + def pixel_addr(x, y): + """Translate an x,y coordinate to a pixel index.""" + return (x << 4) - y + (6 if x <= 5 else -82) diff --git a/adafruit_is31fl3731/scroll_phat_hd.py b/adafruit_is31fl3731/scroll_phat_hd.py new file mode 100644 index 0000000..9504a36 --- /dev/null +++ b/adafruit_is31fl3731/scroll_phat_hd.py @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_is31fl3731.scroll_phat_hd` +==================================================== + +CircuitPython driver for the Pimoroni 17x7 Scroll pHAT HD. + + +* Author: David Glaude + +Implementation Notes +-------------------- + +**Hardware:** + +* `Pimoroni 17x7 Scroll pHAT HD + `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +# imports +from . import IS31FL3731 + + +class ScrollPhatHD(IS31FL3731): + """Supports the Scroll pHAT HD by Pimoroni""" + + width = 17 + height = 7 + + @staticmethod + def pixel_addr(x, y): + """Translate an x,y coordinate to a pixel index.""" + if x <= 8: + x = 8 - x + y = 6 - y + else: + x = x - 8 + y = y - 8 + return x * 16 + y diff --git a/docs/_static/favicon.ico.license b/docs/_static/favicon.ico.license new file mode 100644 index 0000000..86a3fbf --- /dev/null +++ b/docs/_static/favicon.ico.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries + +SPDX-License-Identifier: CC-BY-4.0 diff --git a/docs/api.rst b/docs/api.rst index 49effac..6a34fc9 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -3,3 +3,18 @@ .. automodule:: adafruit_is31fl3731 :members: + +.. automodule:: adafruit_is31fl3731.charlie_bonnet + :members: + +.. automodule:: adafruit_is31fl3731.charlie_wing + :members: + +.. automodule:: adafruit_is31fl3731.matrix + :members: + +.. automodule:: adafruit_is31fl3731.scroll_phat_hd + :members: + +.. automodule:: adafruit_is31fl3731.led_shim + :members: diff --git a/docs/api.rst.license b/docs/api.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/api.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index ff09973..1137aba 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import sys diff --git a/docs/examples.rst b/docs/examples.rst index 3c7e1f8..6c51f3d 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -7,9 +7,11 @@ Ensure your device works with this simple test. :caption: examples/is31fl3731_simpletest.py :linenos: -Other Examples +Matrix Examples --------------- +Other examples working on matrix display. + .. literalinclude:: ../examples/is31fl3731_blink_example.py :caption: examples/is31fl3731_blink_example.py :linenos: @@ -25,3 +27,31 @@ Other Examples .. literalinclude:: ../examples/is31fl3731_wave_example.py :caption: examples/is31fl3731_wave_example.py :linenos: + +Pillow Examples +--------------- + +Examples that utilize the Python Imaging Library (Pillow) for use on (Linux) +computers that are using CPython with Adafruit Blinka to support CircuitPython +libraries. CircuitPython does not support PIL/pillow (python imaging library)! + +.. literalinclude:: ../examples/is31fl3731_pillow_animated_gif.py + :caption: examples/is31fl3731_pillow_animated_gif.py + :linenos: + +.. literalinclude:: ../examples/is31fl3731_pillow_marquee.py + :caption: examples/is31fl3731_pillow_marquee.py + :linenos: + +.. literalinclude:: ../examples/is31fl3731_pillow_numbers.py + :caption: examples/is31fl3731_pillow_numbers.py + :linenos: + +Led Shim Example +---------------- + +Example that work on the RGB Led Shim. + +.. literalinclude:: ../examples/is31fl3731_ledshim_rainbow.py + :caption: examples/is31fl3731_ledshim_rainbow.py + :linenos: diff --git a/docs/examples.rst.license b/docs/examples.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/examples.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/examples/is31fl3731_blink_example.py b/examples/is31fl3731_blink_example.py index 5319879..bbd8a32 100644 --- a/examples/is31fl3731_blink_example.py +++ b/examples/is31fl3731_blink_example.py @@ -1,20 +1,32 @@ -import busio +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import board -import adafruit_is31fl3731 +import busio + +# uncomment next line if you are using Feather CharlieWing LED 15 x 7 +from adafruit_is31fl3731.charlie_wing import CharlieWing as Display + +# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix +# from adafruit_is31fl3731.matrix import Matrix as Display +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +# from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display +# uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout +# from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display + +# uncomment this line if you use a Pico, here with SCL=GP21 and SDA=GP20. +# i2c = busio.I2C(board.GP21, board.GP20) i2c = busio.I2C(board.SCL, board.SDA) # array pattern in bits; top row-> bottom row, 8 bits in each row an_arrow = bytearray((0x08, 0x0C, 0xFE, 0xFF, 0xFE, 0x0C, 0x08, 0x00, 0x00)) -# initial display using Feather CharlieWing LED 15 x 7 -display = adafruit_is31fl3731.CharlieWing(i2c) -# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.CharlieBonnet(i2c) -# initial display using Pimoroni Scroll Phat HD LED 17 x 7 -# display = adafruit_is31fl3731.ScrollPhatHD(i2c) +display = Display(i2c) + +offset = (display.width - 8) // 2 # first load the frame with the arrows; moves the an_arrow to the right in each # frame @@ -25,7 +37,7 @@ for x in range(8): bit = 1 << (7 - x) & row if bit: - display.pixel(x + 4, y, 50, blink=True) + display.pixel(x + offset, y, 50, blink=True) display.blink(1000) # ranges from 270 to 2159; smaller the number to faster blink display.sleep(False) # turn display on diff --git a/examples/is31fl3731_frame_example.py b/examples/is31fl3731_frame_example.py index b678daa..648cfbe 100644 --- a/examples/is31fl3731_frame_example.py +++ b/examples/is31fl3731_frame_example.py @@ -1,27 +1,36 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time import board import busio -import adafruit_is31fl3731 + +# uncomment next line if you are using Feather CharlieWing LED 15 x 7 +from adafruit_is31fl3731.charlie_wing import CharlieWing as Display + +# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix +# from adafruit_is31fl3731.matrix import Matrix as Display +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +# from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display +# uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout +# from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display + +# uncomment this line if you use a Pico, here with SCL=GP21 and SDA=GP20. +# i2c = busio.I2C(board.GP21, board.GP20) i2c = busio.I2C(board.SCL, board.SDA) # arrow pattern in bits; top row-> bottom row, 8 bits in each row arrow = bytearray((0x08, 0x0C, 0xFE, 0xFF, 0xFE, 0x0C, 0x08, 0x00, 0x00)) -# initial display using Feather CharlieWing LED 15 x 7 -display = adafruit_is31fl3731.CharlieWing(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.CharlieBonnet(i2c) -# initial display using Pimoroni Scroll Phat HD LED 17 x 7 -# display = adafruit_is31fl3731.ScrollPhatHD(i2c) - +display = Display(i2c) # first load the frame with the arrows; moves the arrow to the right in each # frame display.sleep(True) # turn display off while frames are updated -for frame in range(8): +for frame in range(display.width - 8): display.frame(frame, show=False) display.fill(0) for y in range(display.height): diff --git a/examples/is31fl3731_keybow_2040_rainbow.py b/examples/is31fl3731_keybow_2040_rainbow.py new file mode 100644 index 0000000..92088a1 --- /dev/null +++ b/examples/is31fl3731_keybow_2040_rainbow.py @@ -0,0 +1,86 @@ +# SPDX-FileCopyrightText: 2021 Sandy Macdonald +# SPDX-License-Identifier: MIT + +""" +Example to display a rainbow animation on the RGB LED keys of the +Keybow 2040. + +Usage: +Rename this file code.py and pop it on your Keybow 2040's +CIRCUITPY drive. + +This example is for use on the Keybow 2040 only, due to the way +that the LEDs are mapped out. + +Author(s): Sandy Macdonald. +""" + +import time +import math +import board + +import adafruit_is31fl3731 + +# pylint: disable=inconsistent-return-statements +# pylint: disable=too-many-return-statements +# pylint: disable=invalid-name + + +def hsv_to_rgb(hue, sat, val): + """ + Convert HSV colour to RGB + + :param hue: hue; 0.0-1.0 + :param sat: saturation; 0.0-1.0 + :param val: value; 0.0-1.0 + """ + + if sat == 0.0: + return (val, val, val) + + i = int(hue * 6.0) + + p = val * (1.0 - sat) + f = (hue * 6.0) - i + q = val * (1.0 - sat * f) + t = val * (1.0 - sat * (1.0 - f)) + + i %= 6 + + if i == 0: + return (val, t, p) + if i == 1: + return (q, val, p) + if i == 2: + return (p, val, t) + if i == 3: + return (p, q, val) + if i == 4: + return (t, p, val) + if i == 5: + return (val, p, q) + + +i2c = board.I2C() + +# Set up 4x4 RGB matrix of Keybow 2040 +display = adafruit_is31fl3731.Keybow2040(i2c) + +step = 0 + +while True: + step += 1 + for y in range(0, 4): + for x in range(0, 4): + pixel_hue = (x + y + (step / 20)) / 8 + pixel_hue = pixel_hue - int(pixel_hue) + pixel_hue += 0 + pixel_hue = pixel_hue - math.floor(pixel_hue) + + rgb = hsv_to_rgb(pixel_hue, 1, 1) + + display.pixelrgb( + x, y, int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255) + ) + + time.sleep(0.01) diff --git a/examples/is31fl3731_ledshim_rainbow.py b/examples/is31fl3731_ledshim_rainbow.py index 3d658b0..3617c31 100644 --- a/examples/is31fl3731_ledshim_rainbow.py +++ b/examples/is31fl3731_ledshim_rainbow.py @@ -1,44 +1,28 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time import board import busio -import adafruit_is31fl3731 +from adafruit_is31fl3731.led_shim import LedShim as Display i2c = busio.I2C(board.SCL, board.SDA) # initial display if you are using Pimoroni LED SHIM -display = adafruit_is31fl3731.LedShim(i2c) +display = Display(i2c) +# fmt: off # This list 28 colors from a rainbow... rainbow = [ - (255, 0, 0), - (255, 54, 0), - (255, 109, 0), - (255, 163, 0), - (255, 218, 0), - (236, 255, 0), - (182, 255, 0), - (127, 255, 0), - (72, 255, 0), - (18, 255, 0), - (0, 255, 36), - (0, 255, 91), - (0, 255, 145), - (0, 255, 200), - (0, 255, 255), - (0, 200, 255), - (0, 145, 255), - (0, 91, 255), - (0, 36, 255), - (18, 0, 255), - (72, 0, 255), - (127, 0, 255), - (182, 0, 255), - (236, 0, 255), - (255, 0, 218), - (255, 0, 163), - (255, 0, 109), - (255, 0, 54), + (255, 0, 0), (255, 54, 0), (255, 109, 0), (255, 163, 0), + (255, 218, 0), (236, 255, 0), (182, 255, 0), (127, 255, 0), + (72, 255, 0), (18, 255, 0), (0, 255, 36), (0, 255, 91), + (0, 255, 145), (0, 255, 200), (0, 255, 255), (0, 200, 255), + (0, 145, 255), (0, 91, 255), (0, 36, 255), (18, 0, 255), + (72, 0, 255), (127, 0, 255), (182, 0, 255), (236, 0, 255), + (255, 0, 218), (255, 0, 163), (255, 0, 109), (255, 0, 54), ] +# fmt: on for y in range(3): diff --git a/examples/is31fl3731_pillow_animated_gif.py b/examples/is31fl3731_pillow_animated_gif.py index dffbfc9..e33f626 100644 --- a/examples/is31fl3731_pillow_animated_gif.py +++ b/examples/is31fl3731_pillow_animated_gif.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ Example to extract the frames and other parameters from an animated gif and then run the animation on the display. @@ -15,14 +18,19 @@ import sys import board from PIL import Image -import adafruit_is31fl3731 + +# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix +# from adafruit_is31fl3731.matrix import Matrix as Display +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display + +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display i2c = board.I2C() -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -display = adafruit_is31fl3731.CharlieBonnet(i2c) +display = Display(i2c) + # Open the gif if len(sys.argv) < 2: diff --git a/examples/is31fl3731_pillow_marquee.py b/examples/is31fl3731_pillow_marquee.py index 5b24b00..e15d3a5 100644 --- a/examples/is31fl3731_pillow_marquee.py +++ b/examples/is31fl3731_pillow_marquee.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ Example to scroll some text as a marquee @@ -10,17 +13,21 @@ import board from PIL import Image, ImageDraw, ImageFont -import adafruit_is31fl3731 + +# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix +# from adafruit_is31fl3731.matrix import Matrix as Display +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display + +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display SCROLLING_TEXT = "You can display a personal message here..." BRIGHTNESS = 64 # Brightness can be between 0-255 i2c = board.I2C() -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -display = adafruit_is31fl3731.CharlieBonnet(i2c) +display = Display(i2c) # Load a font font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 8) diff --git a/examples/is31fl3731_pillow_numbers.py b/examples/is31fl3731_pillow_numbers.py index 2f298c9..8481c57 100644 --- a/examples/is31fl3731_pillow_numbers.py +++ b/examples/is31fl3731_pillow_numbers.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ Example to utilize the Python Imaging Library (Pillow) and draw bitmapped text to 8 frames and then run autoplay on those frames. @@ -11,16 +14,20 @@ import board from PIL import Image, ImageDraw, ImageFont -import adafruit_is31fl3731 + +# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix +# from adafruit_is31fl3731.matrix import Matrix as Display +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display + +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display BRIGHTNESS = 32 # Brightness can be between 0-255 i2c = board.I2C() -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -display = adafruit_is31fl3731.CharlieBonnet(i2c) +display = Display(i2c) display.fill(0) diff --git a/examples/is31fl3731_simpletest.py b/examples/is31fl3731_simpletest.py index 221c8b3..50b87b1 100644 --- a/examples/is31fl3731_simpletest.py +++ b/examples/is31fl3731_simpletest.py @@ -1,20 +1,27 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import board import busio -import adafruit_is31fl3731 - -i2c = busio.I2C(board.SCL, board.SDA) -# initialize display using Feather CharlieWing LED 15 x 7 -display = adafruit_is31fl3731.CharlieWing(i2c) +# uncomment next line if you are using Feather CharlieWing LED 15 x 7 +from adafruit_is31fl3731.charlie_wing import CharlieWing as Display # uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) - +# from adafruit_is31fl3731.matrix import Matrix as Display # uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet -# display = adafruit_is31fl3731.CharlieBonnet(i2c) +# from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display +# uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout +# from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display + +# uncomment this line if you use a Pico, here with SCL=GP21 and SDA=GP20. +# i2c = busio.I2C(board.GP21, board.GP20) + +i2c = busio.I2C(board.SCL, board.SDA) -# initial display using Pimoroni Scroll Phat HD LED 17 x 7 -# display = adafruit_is31fl3731.ScrollPhatHD(i2c) +display = Display(i2c) # draw a box on the display # first draw the top and bottom edges diff --git a/examples/is31fl3731_text_example.py b/examples/is31fl3731_text_example.py index e570176..66d64a6 100644 --- a/examples/is31fl3731_text_example.py +++ b/examples/is31fl3731_text_example.py @@ -1,19 +1,28 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import board import busio import adafruit_framebuf -import adafruit_is31fl3731 +# uncomment next line if you are using Feather CharlieWing LED 15 x 7 +# from adafruit_is31fl3731.charlie_wing import CharlieWing as Display +# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix +# from adafruit_is31fl3731.matrix import Matrix as Display +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display + +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display +# uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout +# from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display + +# uncomment this line if you use a Pico, here with SCL=GP21 and SDA=GP20. +# i2c = busio.I2C(board.GP21, board.GP20) i2c = busio.I2C(board.SCL, board.SDA) -# initial display using Feather CharlieWing LED 15 x 7 -# display = adafruit_is31fl3731.CharlieWing(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) -# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -display = adafruit_is31fl3731.CharlieBonnet(i2c) -# initial display using Pimoroni Scroll Phat HD LED 17 x 7 -# display = adafruit_is31fl3731.ScrollPhatHD(i2c) +display = Display(i2c) text_to_show = "Adafruit!!" diff --git a/examples/is31fl3731_wave_example.py b/examples/is31fl3731_wave_example.py index 332f0a5..5afa39c 100644 --- a/examples/is31fl3731_wave_example.py +++ b/examples/is31fl3731_wave_example.py @@ -1,46 +1,34 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import board import busio -import adafruit_is31fl3731 + +# uncomment next line if you are using Feather CharlieWing LED 15 x 7 +from adafruit_is31fl3731.charlie_wing import CharlieWing as Display + +# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix +# from adafruit_is31fl3731.matrix import Matrix as Display +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +# from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display +# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 +# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display +# uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout +# from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display + +# uncomment this line if you use a Pico, here with SCL=GP21 and SDA=GP20. +# i2c = busio.I2C(board.GP21, board.GP20) i2c = busio.I2C(board.SCL, board.SDA) -sweep = [ - 1, - 2, - 3, - 4, - 6, - 8, - 10, - 15, - 20, - 30, - 40, - 60, - 60, - 40, - 30, - 20, - 15, - 10, - 8, - 6, - 4, - 3, - 2, - 1, -] +# fmt: off +sweep = [ 1, 2, 3, 4, 6, 8, 10, 15, 20, 30, 40, 60, + 60, 40, 30, 20, 15, 10, 8, 6, 4, 3, 2, 1, ] +# fmt: on frame = 0 -# initialize display using Feather CharlieWing LED 15 x 7 -display = adafruit_is31fl3731.CharlieWing(i2c) -# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix -# display = adafruit_is31fl3731.Matrix(i2c) -# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet -# display = adafruit_is31fl3731.CharlieBonnet(i2c) -# initial display using Pimoroni Scroll Phat HD LED 17 x 7 -# display = adafruit_is31fl3731.ScrollPhatHD(i2c) +display = Display(i2c) while True: for incr in range(24): diff --git a/requirements.txt b/requirements.txt index 2b802ba..c4920b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + Adafruit-Blinka -adafruit-circuitpython-framebuf \ No newline at end of file +adafruit-circuitpython-framebuf diff --git a/setup.py b/setup.py index 6204d76..c5fb2a4 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + """A setuptools based setup module. See: @@ -49,5 +53,5 @@ "breakout hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=["adafruit_is31fl3731"], + packages=["adafruit_is31fl3731"], )