├── .gitattributes ├── .github ├── PULL_REQUEST_TEMPLATE │ └── adafruit_circuitpython_pr.md └── workflows │ ├── build.yml │ ├── failure-help-text.yml │ ├── release_gh.yml │ └── release_pypi.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── LICENSES ├── CC-BY-4.0.txt ├── MIT.txt └── Unlicense.txt ├── README.rst ├── README.rst.license ├── adafruit_ht16k33 ├── __init__.py ├── animations.py ├── bargraph.py ├── ht16k33.py ├── matrix.py └── segments.py ├── docs ├── _static │ ├── favicon.ico │ └── favicon.ico.license ├── api.rst ├── api.rst.license ├── conf.py ├── examples.rst ├── examples.rst.license ├── index.rst ├── index.rst.license └── requirements.txt ├── examples ├── ht16k33_animation_demo.py ├── ht16k33_bicolor24_simpletest.py ├── ht16k33_matrix_multi_display.py ├── ht16k33_matrix_pillow_image.py ├── ht16k33_matrix_simpletest.py ├── ht16k33_matrix_text_example.py ├── ht16k33_segments_14x4_demo.py ├── ht16k33_segments_7x4customchars.py ├── ht16k33_segments_multi_display.py ├── ht16k33_segments_non_blocking_marquee.py └── ht16k33_segments_simpletest.py ├── optional_requirements.txt ├── pyproject.toml ├── requirements.txt └── ruff.toml /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | .py text eol=lf 6 | .rst text eol=lf 7 | .txt text eol=lf 8 | .yaml text eol=lf 9 | .toml text eol=lf 10 | .license text eol=lf 11 | .md text eol=lf 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.5.0 8 | hooks: 9 | - id: check-yaml 10 | - id: end-of-file-fixer 11 | - id: trailing-whitespace 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.3.4 14 | hooks: 15 | - id: ruff-format 16 | - id: ruff 17 | args: ["--fix"] 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v3.0.1 20 | hooks: 21 | - id: reuse 22 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | build: 15 | os: ubuntu-lts-latest 16 | tools: 17 | python: "3" 18 | 19 | python: 20 | install: 21 | - requirements: docs/requirements.txt 22 | - requirements: requirements.txt 23 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Adafruit Community Code of Conduct 8 | 9 | ## Our Pledge 10 | 11 | In the interest of fostering an open and welcoming environment, we as 12 | contributors and leaders pledge to making participation in our project and 13 | our community a harassment-free experience for everyone, regardless of age, body 14 | size, disability, ethnicity, gender identity and expression, level or type of 15 | experience, education, socio-economic status, nationality, personal appearance, 16 | race, religion, or sexual identity and orientation. 17 | 18 | ## Our Standards 19 | 20 | We are committed to providing a friendly, safe and welcoming environment for 21 | all. 22 | 23 | Examples of behavior that contributes to creating a positive environment 24 | include: 25 | 26 | * Be kind and courteous to others 27 | * Using welcoming and inclusive language 28 | * Being respectful of differing viewpoints and experiences 29 | * Collaborating with other community members 30 | * Gracefully accepting constructive criticism 31 | * Focusing on what is best for the community 32 | * Showing empathy towards other community members 33 | 34 | Examples of unacceptable behavior by participants include: 35 | 36 | * The use of sexualized language or imagery and sexual attention or advances 37 | * The use of inappropriate images, including in a community member's avatar 38 | * The use of inappropriate language, including in a community member's nickname 39 | * Any spamming, flaming, baiting or other attention-stealing behavior 40 | * Excessive or unwelcome helping; answering outside the scope of the question 41 | asked 42 | * Trolling, insulting/derogatory comments, and personal or political attacks 43 | * Promoting or spreading disinformation, lies, or conspiracy theories against 44 | a person, group, organisation, project, or community 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate 49 | 50 | The goal of the standards and moderation guidelines outlined here is to build 51 | and maintain a respectful community. We ask that you don’t just aim to be 52 | "technically unimpeachable", but rather try to be your best self. 53 | 54 | We value many things beyond technical expertise, including collaboration and 55 | supporting others within our community. Providing a positive experience for 56 | other community members can have a much more significant impact than simply 57 | providing the correct answer. 58 | 59 | ## Our Responsibilities 60 | 61 | Project leaders are responsible for clarifying the standards of acceptable 62 | behavior and are expected to take appropriate and fair corrective action in 63 | response to any instances of unacceptable behavior. 64 | 65 | Project leaders have the right and responsibility to remove, edit, or 66 | reject messages, comments, commits, code, issues, and other contributions 67 | that are not aligned to this Code of Conduct, or to ban temporarily or 68 | permanently any community member for other behaviors that they deem 69 | inappropriate, threatening, offensive, or harmful. 70 | 71 | ## Moderation 72 | 73 | Instances of behaviors that violate the Adafruit Community Code of Conduct 74 | may be reported by any member of the community. Community members are 75 | encouraged to report these situations, including situations they witness 76 | involving other community members. 77 | 78 | You may report in the following ways: 79 | 80 | In any situation, you may send an email to . 81 | 82 | On the Adafruit Discord, you may send an open message from any channel 83 | to all Community Moderators by tagging @community moderators. You may 84 | also send an open message from any channel, or a direct message to 85 | @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, 86 | @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. 87 | 88 | Email and direct message reports will be kept confidential. 89 | 90 | In situations on Discord where the issue is particularly egregious, possibly 91 | illegal, requires immediate action, or violates the Discord terms of service, 92 | you should also report the message directly to Discord. 93 | 94 | These are the steps for upholding our community’s standards of conduct. 95 | 96 | 1. Any member of the community may report any situation that violates the 97 | Adafruit Community Code of Conduct. All reports will be reviewed and 98 | investigated. 99 | 2. If the behavior is an egregious violation, the community member who 100 | committed the violation may be banned immediately, without warning. 101 | 3. Otherwise, moderators will first respond to such behavior with a warning. 102 | 4. Moderators follow a soft "three strikes" policy - the community member may 103 | be given another chance, if they are receptive to the warning and change their 104 | behavior. 105 | 5. If the community member is unreceptive or unreasonable when warned by a 106 | moderator, or the warning goes unheeded, they may be banned for a first or 107 | second offense. Repeated offenses will result in the community member being 108 | banned. 109 | 110 | ## Scope 111 | 112 | This Code of Conduct and the enforcement policies listed above apply to all 113 | Adafruit Community venues. This includes but is not limited to any community 114 | spaces (both public and private), the entire Adafruit Discord server, and 115 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 116 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 117 | interaction at a conference. 118 | 119 | This Code of Conduct applies both within project spaces and in public spaces 120 | when an individual is representing the project or its community. As a community 121 | member, you are representing our community, and are expected to behave 122 | accordingly. 123 | 124 | ## Attribution 125 | 126 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 127 | version 1.4, available at 128 | , 129 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 130 | 131 | For other projects adopting the Adafruit Community Code of 132 | Conduct, please contact the maintainers of those projects for enforcement. 133 | If you wish to use this code of conduct for your own project, consider 134 | explicitly mentioning your moderation policy or making a copy with your 135 | own moderation policy so as to avoid confusion. 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Radomir Dopieralski & Tony DiCola for Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSES/CC-BY-4.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 4.0 International Creative Commons Corporation 2 | ("Creative Commons") is not a law firm and does not provide legal services 3 | or legal advice. Distribution of Creative Commons public licenses does not 4 | create a lawyer-client or other relationship. Creative Commons makes its licenses 5 | and related information available on an "as-is" basis. Creative Commons gives 6 | no warranties regarding its licenses, any material licensed under their terms 7 | and conditions, or any related information. Creative Commons disclaims all 8 | liability for damages resulting from their use to the fullest extent possible. 9 | 10 | Using Creative Commons Public Licenses 11 | 12 | Creative Commons public licenses provide a standard set of terms and conditions 13 | that creators and other rights holders may use to share original works of 14 | authorship and other material subject to copyright and certain other rights 15 | specified in the public license below. The following considerations are for 16 | informational purposes only, are not exhaustive, and do not form part of our 17 | licenses. 18 | 19 | Considerations for licensors: Our public licenses are intended for use by 20 | those authorized to give the public permission to use material in ways otherwise 21 | restricted by copyright and certain other rights. Our licenses are irrevocable. 22 | Licensors should read and understand the terms and conditions of the license 23 | they choose before applying it. Licensors should also secure all rights necessary 24 | before applying our licenses so that the public can reuse the material as 25 | expected. Licensors should clearly mark any material not subject to the license. 26 | This includes other CC-licensed material, or material used under an exception 27 | or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors 28 | 29 | Considerations for the public: By using one of our public licenses, a licensor 30 | grants the public permission to use the licensed material under specified 31 | terms and conditions. If the licensor's permission is not necessary for any 32 | reason–for example, because of any applicable exception or limitation to copyright–then 33 | that use is not regulated by the license. Our licenses grant only permissions 34 | under copyright and certain other rights that a licensor has authority to 35 | grant. Use of the licensed material may still be restricted for other reasons, 36 | including because others have copyright or other rights in the material. A 37 | licensor may make special requests, such as asking that all changes be marked 38 | or described. Although not required by our licenses, you are encouraged to 39 | respect those requests where reasonable. More considerations for the public 40 | : wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution 41 | 4.0 International Public License 42 | 43 | By exercising the Licensed Rights (defined below), You accept and agree to 44 | be bound by the terms and conditions of this Creative Commons Attribution 45 | 4.0 International Public License ("Public License"). To the extent this Public 46 | License may be interpreted as a contract, You are granted the Licensed Rights 47 | in consideration of Your acceptance of these terms and conditions, and the 48 | Licensor grants You such rights in consideration of benefits the Licensor 49 | receives from making the Licensed Material available under these terms and 50 | conditions. 51 | 52 | Section 1 – Definitions. 53 | 54 | a. Adapted Material means material subject to Copyright and Similar Rights 55 | that is derived from or based upon the Licensed Material and in which the 56 | Licensed Material is translated, altered, arranged, transformed, or otherwise 57 | modified in a manner requiring permission under the Copyright and Similar 58 | Rights held by the Licensor. For purposes of this Public License, where the 59 | Licensed Material is a musical work, performance, or sound recording, Adapted 60 | Material is always produced where the Licensed Material is synched in timed 61 | relation with a moving image. 62 | 63 | b. Adapter's License means the license You apply to Your Copyright and Similar 64 | Rights in Your contributions to Adapted Material in accordance with the terms 65 | and conditions of this Public License. 66 | 67 | c. Copyright and Similar Rights means copyright and/or similar rights closely 68 | related to copyright including, without limitation, performance, broadcast, 69 | sound recording, and Sui Generis Database Rights, without regard to how the 70 | rights are labeled or categorized. For purposes of this Public License, the 71 | rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 72 | 73 | d. Effective Technological Measures means those measures that, in the absence 74 | of proper authority, may not be circumvented under laws fulfilling obligations 75 | under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, 76 | and/or similar international agreements. 77 | 78 | e. Exceptions and Limitations means fair use, fair dealing, and/or any other 79 | exception or limitation to Copyright and Similar Rights that applies to Your 80 | use of the Licensed Material. 81 | 82 | f. Licensed Material means the artistic or literary work, database, or other 83 | material to which the Licensor applied this Public License. 84 | 85 | g. Licensed Rights means the rights granted to You subject to the terms and 86 | conditions of this Public License, which are limited to all Copyright and 87 | Similar Rights that apply to Your use of the Licensed Material and that the 88 | Licensor has authority to license. 89 | 90 | h. Licensor means the individual(s) or entity(ies) granting rights under this 91 | Public License. 92 | 93 | i. Share means to provide material to the public by any means or process that 94 | requires permission under the Licensed Rights, such as reproduction, public 95 | display, public performance, distribution, dissemination, communication, or 96 | importation, and to make material available to the public including in ways 97 | that members of the public may access the material from a place and at a time 98 | individually chosen by them. 99 | 100 | j. Sui Generis Database Rights means rights other than copyright resulting 101 | from Directive 96/9/EC of the European Parliament and of the Council of 11 102 | March 1996 on the legal protection of databases, as amended and/or succeeded, 103 | as well as other essentially equivalent rights anywhere in the world. 104 | 105 | k. You means the individual or entity exercising the Licensed Rights under 106 | this Public License. Your has a corresponding meaning. 107 | 108 | Section 2 – Scope. 109 | 110 | a. License grant. 111 | 112 | 1. Subject to the terms and conditions of this Public License, the Licensor 113 | hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, 114 | irrevocable license to exercise the Licensed Rights in the Licensed Material 115 | to: 116 | 117 | A. reproduce and Share the Licensed Material, in whole or in part; and 118 | 119 | B. produce, reproduce, and Share Adapted Material. 120 | 121 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions 122 | and Limitations apply to Your use, this Public License does not apply, and 123 | You do not need to comply with its terms and conditions. 124 | 125 | 3. Term. The term of this Public License is specified in Section 6(a). 126 | 127 | 4. Media and formats; technical modifications allowed. The Licensor authorizes 128 | You to exercise the Licensed Rights in all media and formats whether now known 129 | or hereafter created, and to make technical modifications necessary to do 130 | so. The Licensor waives and/or agrees not to assert any right or authority 131 | to forbid You from making technical modifications necessary to exercise the 132 | Licensed Rights, including technical modifications necessary to circumvent 133 | Effective Technological Measures. For purposes of this Public License, simply 134 | making modifications authorized by this Section 2(a)(4) never produces Adapted 135 | Material. 136 | 137 | 5. Downstream recipients. 138 | 139 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed 140 | Material automatically receives an offer from the Licensor to exercise the 141 | Licensed Rights under the terms and conditions of this Public License. 142 | 143 | B. No downstream restrictions. You may not offer or impose any additional 144 | or different terms or conditions on, or apply any Effective Technological 145 | Measures to, the Licensed Material if doing so restricts exercise of the Licensed 146 | Rights by any recipient of the Licensed Material. 147 | 148 | 6. No endorsement. Nothing in this Public License constitutes or may be construed 149 | as permission to assert or imply that You are, or that Your use of the Licensed 150 | Material is, connected with, or sponsored, endorsed, or granted official status 151 | by, the Licensor or others designated to receive attribution as provided in 152 | Section 3(a)(1)(A)(i). 153 | 154 | b. Other rights. 155 | 156 | 1. Moral rights, such as the right of integrity, are not licensed under this 157 | Public License, nor are publicity, privacy, and/or other similar personality 158 | rights; however, to the extent possible, the Licensor waives and/or agrees 159 | not to assert any such rights held by the Licensor to the limited extent necessary 160 | to allow You to exercise the Licensed Rights, but not otherwise. 161 | 162 | 2. Patent and trademark rights are not licensed under this Public License. 163 | 164 | 3. To the extent possible, the Licensor waives any right to collect royalties 165 | from You for the exercise of the Licensed Rights, whether directly or through 166 | a collecting society under any voluntary or waivable statutory or compulsory 167 | licensing scheme. In all other cases the Licensor expressly reserves any right 168 | to collect such royalties. 169 | 170 | Section 3 – License Conditions. 171 | 172 | Your exercise of the Licensed Rights is expressly made subject to the following 173 | conditions. 174 | 175 | a. Attribution. 176 | 177 | 1. If You Share the Licensed Material (including in modified form), You must: 178 | 179 | A. retain the following if it is supplied by the Licensor with the Licensed 180 | Material: 181 | 182 | i. identification of the creator(s) of the Licensed Material and any others 183 | designated to receive attribution, in any reasonable manner requested by the 184 | Licensor (including by pseudonym if designated); 185 | 186 | ii. a copyright notice; 187 | 188 | iii. a notice that refers to this Public License; 189 | 190 | iv. a notice that refers to the disclaimer of warranties; 191 | 192 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 193 | 194 | B. indicate if You modified the Licensed Material and retain an indication 195 | of any previous modifications; and 196 | 197 | C. indicate the Licensed Material is licensed under this Public License, and 198 | include the text of, or the URI or hyperlink to, this Public License. 199 | 200 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner 201 | based on the medium, means, and context in which You Share the Licensed Material. 202 | For example, it may be reasonable to satisfy the conditions by providing a 203 | URI or hyperlink to a resource that includes the required information. 204 | 205 | 3. If requested by the Licensor, You must remove any of the information required 206 | by Section 3(a)(1)(A) to the extent reasonably practicable. 207 | 208 | 4. If You Share Adapted Material You produce, the Adapter's License You apply 209 | must not prevent recipients of the Adapted Material from complying with this 210 | Public License. 211 | 212 | Section 4 – Sui Generis Database Rights. 213 | 214 | Where the Licensed Rights include Sui Generis Database Rights that apply to 215 | Your use of the Licensed Material: 216 | 217 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, 218 | reuse, reproduce, and Share all or a substantial portion of the contents of 219 | the database; 220 | 221 | b. if You include all or a substantial portion of the database contents in 222 | a database in which You have Sui Generis Database Rights, then the database 223 | in which You have Sui Generis Database Rights (but not its individual contents) 224 | is Adapted Material; and 225 | 226 | c. You must comply with the conditions in Section 3(a) if You Share all or 227 | a substantial portion of the contents of the database. 228 | 229 | For the avoidance of doubt, this Section 4 supplements and does not replace 230 | Your obligations under this Public License where the Licensed Rights include 231 | other Copyright and Similar Rights. 232 | 233 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 234 | 235 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, 236 | the Licensor offers the Licensed Material as-is and as-available, and makes 237 | no representations or warranties of any kind concerning the Licensed Material, 238 | whether express, implied, statutory, or other. This includes, without limitation, 239 | warranties of title, merchantability, fitness for a particular purpose, non-infringement, 240 | absence of latent or other defects, accuracy, or the presence or absence of 241 | errors, whether or not known or discoverable. Where disclaimers of warranties 242 | are not allowed in full or in part, this disclaimer may not apply to You. 243 | 244 | b. To the extent possible, in no event will the Licensor be liable to You 245 | on any legal theory (including, without limitation, negligence) or otherwise 246 | for any direct, special, indirect, incidental, consequential, punitive, exemplary, 247 | or other losses, costs, expenses, or damages arising out of this Public License 248 | or use of the Licensed Material, even if the Licensor has been advised of 249 | the possibility of such losses, costs, expenses, or damages. Where a limitation 250 | of liability is not allowed in full or in part, this limitation may not apply 251 | to You. 252 | 253 | c. The disclaimer of warranties and limitation of liability provided above 254 | shall be interpreted in a manner that, to the extent possible, most closely 255 | approximates an absolute disclaimer and waiver of all liability. 256 | 257 | Section 6 – Term and Termination. 258 | 259 | a. This Public License applies for the term of the Copyright and Similar Rights 260 | licensed here. However, if You fail to comply with this Public License, then 261 | Your rights under this Public License terminate automatically. 262 | 263 | b. Where Your right to use the Licensed Material has terminated under Section 264 | 6(a), it reinstates: 265 | 266 | 1. automatically as of the date the violation is cured, provided it is cured 267 | within 30 days of Your discovery of the violation; or 268 | 269 | 2. upon express reinstatement by the Licensor. 270 | 271 | c. For the avoidance of doubt, this Section 6(b) does not affect any right 272 | the Licensor may have to seek remedies for Your violations of this Public 273 | License. 274 | 275 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material 276 | under separate terms or conditions or stop distributing the Licensed Material 277 | at any time; however, doing so will not terminate this Public License. 278 | 279 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 280 | 281 | Section 7 – Other Terms and Conditions. 282 | 283 | a. The Licensor shall not be bound by any additional or different terms or 284 | conditions communicated by You unless expressly agreed. 285 | 286 | b. Any arrangements, understandings, or agreements regarding the Licensed 287 | Material not stated herein are separate from and independent of the terms 288 | and conditions of this Public License. 289 | 290 | Section 8 – Interpretation. 291 | 292 | a. For the avoidance of doubt, this Public License does not, and shall not 293 | be interpreted to, reduce, limit, restrict, or impose conditions on any use 294 | of the Licensed Material that could lawfully be made without permission under 295 | this Public License. 296 | 297 | b. To the extent possible, if any provision of this Public License is deemed 298 | unenforceable, it shall be automatically reformed to the minimum extent necessary 299 | to make it enforceable. If the provision cannot be reformed, it shall be severed 300 | from this Public License without affecting the enforceability of the remaining 301 | terms and conditions. 302 | 303 | c. No term or condition of this Public License will be waived and no failure 304 | to comply consented to unless expressly agreed to by the Licensor. 305 | 306 | d. Nothing in this Public License constitutes or may be interpreted as a limitation 307 | upon, or waiver of, any privileges and immunities that apply to the Licensor 308 | or You, including from the legal processes of any jurisdiction or authority. 309 | 310 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative 311 | Commons may elect to apply one of its public licenses to material it publishes 312 | and in those instances will be considered the "Licensor." The text of the 313 | Creative Commons public licenses is dedicated to the public domain under the 314 | CC0 Public Domain Dedication. Except for the limited purpose of indicating 315 | that material is shared under a Creative Commons public license or as otherwise 316 | permitted by the Creative Commons policies published at creativecommons.org/policies, 317 | Creative Commons does not authorize the use of the trademark "Creative Commons" 318 | or any other trademark or logo of Creative Commons without its prior written 319 | consent including, without limitation, in connection with any unauthorized 320 | modifications to any of its public licenses or any other arrangements, understandings, 321 | or agreements concerning use of licensed material. For the avoidance of doubt, 322 | this paragraph does not form part of the public licenses. 323 | 324 | Creative Commons may be contacted at creativecommons.org. 325 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /LICENSES/Unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of this 8 | software dedicate any and all copyright interest in the software to the public 9 | domain. We make this dedication for the benefit of the public at large and 10 | to the detriment of our heirs and successors. We intend this dedication to 11 | be an overt act of relinquishment in perpetuity of all present and future 12 | rights to this software under copyright law. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 19 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, 20 | please refer to 21 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============= 3 | 4 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-ht16k33/badge/?version=latest 5 | :target: https://docs.circuitpython.org/projects/ht16k33/en/latest/ 6 | :alt: Documentation Status 7 | 8 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 9 | :target: https://adafru.it/discord 10 | :alt: Discord 11 | 12 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_HT16K33/workflows/Build%20CI/badge.svg 13 | :target: https://github.com/adafruit/Adafruit_CircuitPython_HT16K33/actions/ 14 | :alt: Build Status 15 | 16 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 17 | :target: https://github.com/astral-sh/ruff 18 | :alt: Code Style: Ruff 19 | 20 | This is a library for using the I²C-based LED matrices with the HT16K33 chip. 21 | It supports both 16x8 and 8x8 matrices, as well as 7- and 14-segment displays. 22 | 23 | * **Notes** 24 | 25 | #. This library is intended for Adafruit CircuitPython's API. For a library compatible with MicroPython machine API see this `library `_. 26 | 27 | #. This library does not work with the Trellis 4x4 LED+Keypad board. For that product use: `CircuitPython Trellis Library `_ 28 | 29 | Dependencies 30 | ============= 31 | This driver depends on: 32 | 33 | * `Adafruit CircuitPython `_ 34 | * `Bus Device `_ 35 | 36 | Please ensure all dependencies are available on the CircuitPython filesystem. 37 | This is easily achieved by downloading 38 | `the Adafruit library and driver bundle `_. 39 | 40 | Installing from PyPI 41 | ==================== 42 | 43 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 44 | PyPI `_. To install for current user: 45 | 46 | .. code-block:: shell 47 | 48 | pip3 install adafruit-circuitpython-ht16k33 49 | 50 | To install system-wide (this may be required in some cases): 51 | 52 | .. code-block:: shell 53 | 54 | sudo pip3 install adafruit-circuitpython-ht16k33 55 | 56 | To install in a virtual environment in your current project: 57 | 58 | .. code-block:: shell 59 | 60 | mkdir project-name && cd project-name 61 | python3 -m venv .venv 62 | source .venv/bin/activate 63 | pip3 install adafruit-circuitpython-ht16k33 64 | 65 | Usage Example 66 | ============= 67 | 68 | .. code-block :: python 69 | 70 | # Import all board pins and bus interface. 71 | import board 72 | import busio 73 | 74 | # Import the HT16K33 LED matrix module. 75 | from adafruit_ht16k33 import matrix 76 | 77 | # Create the I2C interface. 78 | i2c = busio.I2C(board.SCL, board.SDA) 79 | 80 | # Create the matrix class. 81 | # This creates a 16x8 matrix: 82 | matrix = matrix.Matrix16x8(i2c) 83 | # Or this creates a 8x8 matrix: 84 | #matrix = matrix.Matrix8x8(i2c) 85 | # Or this creates a 8x8 bicolor matrix: 86 | #matrix = matrix.Matrix8x8x2 87 | # Finally you can optionally specify a custom I2C address of the HT16k33 like: 88 | #matrix = matrix.Matrix16x8(i2c, address=0x70) 89 | 90 | # Clear the matrix. 91 | matrix.fill(0) 92 | 93 | # Set a pixel in the origin 0,0 position. 94 | matrix[0, 0] = 1 95 | # Set a pixel in the middle 8, 4 position. 96 | matrix[8, 4] = 1 97 | # Set a pixel in the opposite 15, 7 position. 98 | matrix[15, 7] = 1 99 | matrix.show() 100 | 101 | # Change the brightness 102 | matrix.brightness = 8 103 | 104 | # Set the blink rate 105 | matrix.blink_rate = 2 106 | 107 | 108 | Documentation 109 | ============= 110 | 111 | API documentation for this library can be found on `Read the Docs `_. 112 | 113 | For information on building library documentation, please check out `this guide `_. 114 | 115 | Contributing 116 | ============ 117 | 118 | Contributions are welcome! Please read our `Code of Conduct 119 | `_ 120 | before contributing to help this project stay welcoming. 121 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_ht16k33/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_HT16K33/43817d123b003a1fb4cea34c085ef6f5816781e8/adafruit_ht16k33/__init__.py -------------------------------------------------------------------------------- /adafruit_ht16k33/animations.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | 5 | """ 6 | `adafruit_ht16k33.animations` 7 | ============================== 8 | 9 | * Authors: ladyada 10 | 11 | Test script for display animations on an HT16K33 with alphanumeric display 12 | 13 | The display must be initialized with auto_write=False. 14 | 15 | """ 16 | 17 | from time import sleep 18 | 19 | try: 20 | from typing import List 21 | 22 | from adafruit_ht16k33.segments import Seg14x4 23 | except ImportError: 24 | pass 25 | 26 | 27 | N = 16384 28 | M = 8192 29 | L = 4096 30 | K = 2048 31 | J = 1024 32 | I = 512 33 | H = 256 34 | G2 = 128 35 | G1 = 64 36 | F = 32 37 | E = 16 38 | D = 8 39 | C = 4 40 | B = 2 41 | A = 1 42 | 43 | 44 | class Animation: 45 | """Animation class for the htk33 46 | Main driver for all alphanumeric display animations (WIP!!!) 47 | 48 | :param display: HTK33 Display object 49 | 50 | 51 | """ 52 | 53 | def __init__(self, display: Seg14x4) -> None: 54 | self._display = display 55 | 56 | def animate( 57 | self, 58 | digits: List[int], 59 | bitmasks: List[int], 60 | delay: float = 0.2, 61 | auto_write: bool = True, 62 | ) -> None: 63 | """Animate function 64 | 65 | 66 | :param digits: a list of the digits to write to, in order, like [0, 1, 3]. The digits are 67 | 0 to 3 starting at the left most digit. 68 | :param bitmasks: a list of the bitmasks to write, in sequence, to the specified digits. 69 | :param delay: The delay, in seconds (or fractions of), between writing bitmasks to a digit. 70 | :param auto_write: Whether to actually write to the display immediately or not. 71 | 72 | 73 | """ 74 | 75 | if not isinstance(digits, list): 76 | raise ValueError("The first parameter MUST be a list!") 77 | if not isinstance(bitmasks, list): 78 | raise ValueError("The second parameter MUST be a list!") 79 | if delay < 0: 80 | raise ValueError("The delay between frames must be positive!") 81 | for dig in digits: 82 | if not 0 <= dig <= 3: 83 | raise ValueError("Digit value must be an integer in the range: 0-3") 84 | 85 | for bits in bitmasks: 86 | if not 0 <= bits <= 0xFFFF: 87 | raise ValueError("Bitmask value must be an integer in the range: 0-65535") 88 | 89 | self._display.set_digit_raw(dig, bits) 90 | 91 | if auto_write: 92 | self._display.show() 93 | sleep(delay) 94 | 95 | def chase_forward_and_reverse(self, delay: float = 0.2, cycles: int = 5): 96 | """Chase Forward and Reverse Animation""" 97 | 98 | for _ in range(cycles): 99 | self.animate([0, 1, 2, 3], [A, 0], delay) 100 | self.animate([3], [B, C, D, 0], delay) 101 | self.animate([2, 1, 0], [D, 0], delay) 102 | self.animate([0], [E, F, H, G2, 0], delay) 103 | self.animate([1, 2], [G1, G2, 0], delay) 104 | self.animate([3], [G1, J, A, 0], delay) 105 | self.animate([2, 1], [A, 0], delay) 106 | self.animate([0], [A, F, E, D, 0], delay) 107 | self.animate([1, 2], [D, 0], delay) 108 | self.animate([3], [D, C, B, J, G1, 0], delay) 109 | self.animate([2, 1], [G2, G1, 0], delay) 110 | self.animate([0], [H, 0], delay) 111 | 112 | def prelude_to_spinners(self, delay: float = 0.2, cycles: int = 5) -> None: 113 | """Prelude to Spinners Animation""" 114 | 115 | auto_write = False 116 | 117 | for _ in range(cycles): 118 | self.animate([1, 2], [A], 0, auto_write) 119 | self._display.show() 120 | sleep(delay) 121 | 122 | self.animate([0, 3], [A], 0, auto_write) 123 | self._display.show() 124 | sleep(delay) 125 | 126 | self.animate([0], [A + F], 0, auto_write) 127 | self.animate([3], [A + B], 0, auto_write) 128 | self._display.show() 129 | sleep(delay) 130 | 131 | self.animate([0], [A + E + F], 0, auto_write) 132 | self.animate([3], [A + B + C], 0, auto_write) 133 | self._display.show() 134 | sleep(delay) 135 | 136 | self.animate([0], [A + D + E + F], 0, auto_write) 137 | self.animate([3], [A + B + C + D], 0, auto_write) 138 | self._display.show() 139 | sleep(delay) 140 | 141 | self.animate([1], [A + D], 0, auto_write) 142 | self.animate([2], [A + D], 0, auto_write) 143 | self._display.show() 144 | sleep(delay) 145 | 146 | self.animate([1], [A + D + M], 0, auto_write) 147 | self.animate([2], [A + D + K], 0, auto_write) 148 | self._display.show() 149 | sleep(delay) 150 | 151 | self.animate([1], [A + D + M + H], 0, auto_write) 152 | self.animate([2], [A + D + K + J], 0, auto_write) 153 | self._display.show() 154 | sleep(delay) 155 | 156 | self.animate([0], [A + E + F + J + D], 0, auto_write) 157 | self.animate([3], [A + B + C + H + D], 0, auto_write) 158 | self._display.show() 159 | sleep(delay) 160 | 161 | self.animate([0], [A + E + F + J + K + D], 0, auto_write) 162 | self.animate([3], [A + B + C + H + M + D], 0, auto_write) 163 | self._display.show() 164 | sleep(delay) 165 | 166 | self._display.fill(0) 167 | self._display.show() 168 | sleep(delay) 169 | 170 | def spinners(self, delay: float = 0.2, cycles: int = 5) -> None: 171 | """Spinners Animation""" 172 | 173 | auto_write = False 174 | 175 | for _ in range(cycles): 176 | self.animate([0], [H + M], 0, auto_write) 177 | self.animate([1], [J + K], 0, auto_write) 178 | self.animate([2], [H + M], 0, auto_write) 179 | self.animate([3], [J + K], 0, auto_write) 180 | self._display.show() 181 | sleep(delay) 182 | 183 | self.animate([0], [G1 + G2], 0, auto_write) 184 | self.animate([1], [G1 + G2], 0, auto_write) 185 | self.animate([2], [G1 + G2], 0, auto_write) 186 | self.animate([3], [G1 + G2], 0, auto_write) 187 | self._display.show() 188 | sleep(delay) 189 | 190 | self.animate([0], [J + K], 0, auto_write) 191 | self.animate([1], [H + M], 0, auto_write) 192 | self.animate([2], [J + K], 0, auto_write) 193 | self.animate([3], [H + M], 0, auto_write) 194 | self._display.show() 195 | sleep(delay) 196 | 197 | self._display.fill(0) 198 | 199 | def enclosed_spinners(self, delay: float = 0.2, cycles: int = 5) -> None: 200 | """Enclosed Spinner Animation""" 201 | 202 | auto_write = False 203 | 204 | for _ in range(cycles): 205 | self.animate([0], [A + D + E + F + H + M], 0, auto_write) 206 | self.animate([1], [A + D + J + K], 0, auto_write) 207 | self.animate([2], [A + D + H + M], 0, auto_write) 208 | self.animate([3], [A + B + C + D + J + K], 0, auto_write) 209 | self._display.show() 210 | sleep(delay) 211 | 212 | self.animate([0], [A + D + E + F + G1 + G2], 0, auto_write) 213 | self.animate([1], [A + D + G1 + G2], 0, auto_write) 214 | self.animate([2], [A + D + G1 + G2], 0, auto_write) 215 | self.animate([3], [A + B + C + D + G1 + G2], 0, auto_write) 216 | self._display.show() 217 | sleep(delay) 218 | 219 | self.animate([0], [A + D + E + F + J + K], 0, auto_write) 220 | self.animate([1], [A + D + H + M], 0, auto_write) 221 | self.animate([2], [A + D + J + K], 0, auto_write) 222 | self.animate([3], [A + B + C + D + H + M], 0, auto_write) 223 | self._display.show() 224 | sleep(delay) 225 | 226 | self._display.fill(0) 227 | 228 | def count_down(self) -> None: 229 | """Countdown Method""" 230 | 231 | auto_write = False 232 | numbers = [ 233 | [A + B + C + D + G1 + G2 + N], 234 | [A + B + D + E + G1 + G2 + N], 235 | [B + C + N], 236 | ] 237 | 238 | self._display.fill(0) 239 | 240 | for index, number in enumerate(numbers): 241 | self.animate([index], number, 0, auto_write) 242 | self._display.show() 243 | sleep(1) 244 | self._display.fill(0) 245 | sleep(0.5) 246 | 247 | sleep(1) 248 | self._display.fill(0) 249 | -------------------------------------------------------------------------------- /adafruit_ht16k33/bargraph.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `adafruit_ht16k33.bargraph` 7 | =========================== 8 | 9 | * Authors: Carter Nelson for Adafruit Industries 10 | 11 | """ 12 | 13 | from adafruit_ht16k33.ht16k33 import HT16K33 14 | 15 | __version__ = "0.0.0+auto.0" 16 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git" 17 | 18 | 19 | class Bicolor24(HT16K33): 20 | """Bi-color 24-bar bargraph display.""" 21 | 22 | LED_OFF = 0 23 | LED_RED = 1 24 | LED_GREEN = 2 25 | LED_YELLOW = 3 26 | 27 | def __getitem__(self, key: int) -> int: 28 | # map to HT16K33 row (x) and column (y), see schematic 29 | x = key % 4 + 4 * (key // 12) 30 | y = key // 4 - 3 * (key // 12) 31 | # construct the color value and return it 32 | return self._pixel(x, y) | self._pixel(x + 8, y) << 1 33 | 34 | def __setitem__(self, key: int, value: int) -> None: 35 | # map to HT16K33 row (x) and column (y), see schematic 36 | x = key % 4 + 4 * (key // 12) 37 | y = key // 4 - 3 * (key // 12) 38 | # conditionally turn on red LED 39 | self._pixel(x, y, value & 0x01) 40 | # conditionally turn on green LED 41 | self._pixel(x + 8, y, value >> 1) 42 | 43 | def fill(self, color: int) -> None: 44 | """Fill the whole display with the given color. 45 | 46 | :param int color: Whether to fill the display, where 0 is no 47 | color, 1 is red, 2 is green, and 3 is yellow (red + 48 | green) 49 | """ 50 | 51 | what_it_was = self.auto_write 52 | self.auto_write = False 53 | for i in range(24): 54 | self[i] = color 55 | self.show() 56 | self.auto_write = what_it_was 57 | -------------------------------------------------------------------------------- /adafruit_ht16k33/ht16k33.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Radomir Dopieralski 2016 for Adafruit Industries 2 | # SPDX-FileCopyrightText: Tony DiCola 2016 for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | """ 7 | `adafruit_ht16k33.ht16k33` 8 | =========================== 9 | 10 | * Authors: Radomir Dopieralski, Tony DiCola, and Melissa LeBlanc-Williams for Adafruit Industries 11 | 12 | """ 13 | 14 | from adafruit_bus_device import i2c_device 15 | from micropython import const 16 | 17 | try: 18 | from typing import List, Optional, Tuple, Union 19 | 20 | from busio import I2C 21 | except ImportError: 22 | pass 23 | 24 | 25 | __version__ = "0.0.0+auto.0" 26 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git" 27 | 28 | _HT16K33_BLINK_CMD = const(0x80) 29 | _HT16K33_BLINK_DISPLAYON = const(0x01) 30 | _HT16K33_CMD_BRIGHTNESS = const(0xE0) 31 | _HT16K33_OSCILATOR_ON = const(0x21) 32 | 33 | 34 | class HT16K33: 35 | """ 36 | The base class for all displays. Contains common methods. 37 | 38 | :param ~busio.I2C i2c: The I2C bus object 39 | :param int|list|tuple address: The I2C addess(es) of the HT16K33. 40 | :param bool auto_write: True if the display should immediately change when 41 | set. If False, `show` must be called explicitly. 42 | :param float brightness: 0.0 - 1.0 default brightness level. 43 | """ 44 | 45 | def __init__( 46 | self, 47 | i2c: I2C, 48 | address: Union[int, List[int], Tuple[int, ...]] = 0x70, 49 | auto_write: bool = True, 50 | brightness: float = 1.0, 51 | ) -> None: 52 | if isinstance(address, (tuple, list)): 53 | self.i2c_device = [] 54 | for addr in address: 55 | self.i2c_device.append(i2c_device.I2CDevice(i2c, addr)) 56 | else: 57 | self.i2c_device = [i2c_device.I2CDevice(i2c, address)] 58 | self._temp = bytearray(1) 59 | self._buffer_size = 17 60 | self._buffer = bytearray((self._buffer_size) * len(self.i2c_device)) 61 | self._auto_write = auto_write 62 | self.fill(0) 63 | for i, _ in enumerate(self.i2c_device): 64 | self._write_cmd(_HT16K33_OSCILATOR_ON, i) 65 | self._blink_rate = None 66 | self._brightness = None 67 | self.blink_rate = 0 68 | self.brightness = brightness 69 | 70 | def _write_cmd(self, byte: int, i2c_index: int = 0) -> None: 71 | self._temp[0] = byte 72 | with self.i2c_device[i2c_index]: 73 | self.i2c_device[i2c_index].write(self._temp) 74 | 75 | @property 76 | def blink_rate(self) -> int: 77 | """The blink rate. Range 0-3.""" 78 | return self._blink_rate 79 | 80 | @blink_rate.setter 81 | def blink_rate(self, rate: int) -> None: 82 | if not 0 <= rate <= 3: 83 | raise ValueError("Blink rate must be an integer in the range: 0-3") 84 | rate = rate & 0x03 85 | self._blink_rate = rate 86 | for index, _ in enumerate(self.i2c_device): 87 | self._write_cmd(_HT16K33_BLINK_CMD | _HT16K33_BLINK_DISPLAYON | rate << 1, index) 88 | 89 | @property 90 | def brightness(self) -> float: 91 | """The brightness. Range 0.0-1.0""" 92 | return self._brightness 93 | 94 | @brightness.setter 95 | def brightness(self, brightness: float) -> None: 96 | if not 0.0 <= brightness <= 1.0: 97 | raise ValueError("Brightness must be a decimal number in the range: 0.0-1.0") 98 | 99 | self._brightness = brightness 100 | xbright = round(15 * brightness) 101 | xbright = xbright & 0x0F 102 | for index, _ in enumerate(self.i2c_device): 103 | self._write_cmd(_HT16K33_CMD_BRIGHTNESS | xbright, index) 104 | 105 | @property 106 | def auto_write(self) -> bool: 107 | """Auto write updates to the display.""" 108 | return self._auto_write 109 | 110 | @auto_write.setter 111 | def auto_write(self, auto_write: bool) -> None: 112 | if isinstance(auto_write, bool): 113 | self._auto_write = auto_write 114 | else: 115 | raise ValueError("Must set to either True or False.") 116 | 117 | def show(self) -> None: 118 | """Refresh the display and show the changes.""" 119 | for index, i2c_dev in enumerate(self.i2c_device): 120 | with i2c_dev: 121 | # Byte 0 is 0x00, address of LED data register. The remaining 16 122 | # bytes are the display register data to set. 123 | offset = index * self._buffer_size 124 | buffer = self._buffer[offset : offset + self._buffer_size] 125 | i2c_dev.write(buffer) 126 | 127 | def fill(self, color: bool) -> None: 128 | """Fill the whole display with the given color. 129 | 130 | :param bool color: Whether to fill the display 131 | """ 132 | 133 | fill = 0xFF if color else 0x00 134 | for device, _ in enumerate(self.i2c_device): 135 | for i in range(self._buffer_size - 1): 136 | self._buffer[device * self._buffer_size + i + 1] = fill 137 | if self._auto_write: 138 | self.show() 139 | 140 | def _pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]: 141 | offset = ((x // 16) + (y // 8)) * self._buffer_size 142 | addr = 2 * (y % 8) + ((x % 16) // 8) 143 | addr = (addr % 16) + offset 144 | mask = 1 << x % 8 145 | if color is None: 146 | return bool(self._buffer[addr + 1] & mask) 147 | if color: 148 | # set the bit 149 | self._buffer[addr + 1] |= mask 150 | else: 151 | # clear the bit 152 | self._buffer[addr + 1] &= ~mask 153 | if self._auto_write: 154 | self.show() 155 | return None 156 | 157 | def _set_buffer(self, i: int, value: int) -> None: 158 | self._buffer[i + 1] = value # Offset by 1 to move past register address. 159 | 160 | def _get_buffer(self, i: int) -> int: 161 | return self._buffer[i + 1] # Offset by 1 to move past register address. 162 | -------------------------------------------------------------------------------- /adafruit_ht16k33/matrix.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Radomir Dopieralski 2016 for Adafruit Industries 2 | # SPDX-FileCopyrightText: Tony DiCola 2016 for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | """ 7 | adafruit_ht16k33.matrix 8 | ======================= 9 | 10 | """ 11 | 12 | from adafruit_ht16k33.ht16k33 import HT16K33 13 | 14 | try: 15 | from typing import List, Optional, Tuple, Union 16 | 17 | from busio import I2C 18 | from circuitpython_typing.pil import Image 19 | except ImportError: 20 | pass 21 | 22 | 23 | __version__ = "0.0.0+auto.0" 24 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git" 25 | 26 | 27 | class Matrix8x8(HT16K33): 28 | """A single matrix.""" 29 | 30 | _columns = 8 31 | _rows = 8 32 | 33 | def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]: 34 | """Get or set the color of a given pixel. 35 | 36 | :param int x: The x coordinate of the pixel 37 | :param int y: The y coordinate of the pixel 38 | :param bool color: (Optional) The state to set the pixel 39 | :return: If ``color`` was not set, this returns the state of the pixel 40 | :rtype: bool 41 | """ 42 | if not 0 <= x <= 7: 43 | return None 44 | if not 0 <= y <= 7: 45 | return None 46 | x = (x - 1) % 8 47 | return super()._pixel(x, y, color) 48 | 49 | def __getitem__(self, key: Tuple[int, int]) -> Optional[bool]: 50 | x, y = key 51 | return self.pixel(x, y) 52 | 53 | def __setitem__(self, key: Tuple[int, int], value: Optional[bool]) -> None: 54 | x, y = key 55 | self.pixel(x, y, value) 56 | 57 | def shift(self, x: int, y: int, rotate: bool = False) -> None: 58 | """ 59 | Shift pixels by x and y 60 | 61 | :param int x: The x coordinate of the pixel 62 | :param int y: The y coordinate of the pixel 63 | :param bool rotate: (Optional) Rotate the shifted pixels to the left side (default=False) 64 | """ 65 | auto_write = self.auto_write 66 | self._auto_write = False 67 | if x > 0: # Shift Right 68 | for _ in range(x): 69 | for row in range(0, self.rows): 70 | last_pixel = self[self.columns - 1, row] if rotate else 0 71 | for col in range(self.columns - 1, 0, -1): 72 | self[col, row] = self[col - 1, row] 73 | self[0, row] = last_pixel 74 | elif x < 0: # Shift Left 75 | for _ in range(-x): 76 | for row in range(0, self.rows): 77 | last_pixel = self[0, row] if rotate else 0 78 | for col in range(0, self.columns - 1): 79 | self[col, row] = self[col + 1, row] 80 | self[self.columns - 1, row] = last_pixel 81 | if y > 0: # Shift Up 82 | for _ in range(y): 83 | for col in range(0, self.columns): 84 | last_pixel = self[col, self.rows - 1] if rotate else 0 85 | for row in range(self.rows - 1, 0, -1): 86 | self[col, row] = self[col, row - 1] 87 | self[col, 0] = last_pixel 88 | elif y < 0: # Shift Down 89 | for _ in range(-y): 90 | for col in range(0, self.columns): 91 | last_pixel = self[col, 0] if rotate else 0 92 | for row in range(0, self.rows - 1): 93 | self[col, row] = self[col, row + 1] 94 | self[col, self.rows - 1] = last_pixel 95 | self._auto_write = auto_write 96 | if auto_write: 97 | self.show() 98 | 99 | # pylint: enable=too-many-branches 100 | 101 | def shift_right(self, rotate: bool = False) -> None: 102 | """ 103 | Shift all pixels right 104 | 105 | :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False) 106 | """ 107 | self.shift(1, 0, rotate) 108 | 109 | def shift_left(self, rotate: bool = False) -> None: 110 | """ 111 | Shift all pixels left 112 | 113 | :param rotate: (Optional) Rotate the shifted pixels to the right side (default=False) 114 | """ 115 | self.shift(-1, 0, rotate) 116 | 117 | def shift_up(self, rotate: bool = False) -> None: 118 | """ 119 | Shift all pixels up 120 | 121 | :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False) 122 | """ 123 | self.shift(0, 1, rotate) 124 | 125 | def shift_down(self, rotate: bool = False) -> None: 126 | """ 127 | Shift all pixels down 128 | 129 | :param rotate: (Optional) Rotate the shifted pixels to top (default=False) 130 | """ 131 | self.shift(0, -1, rotate) 132 | 133 | def image(self, img: Image) -> None: 134 | """Set buffer to value of Python Imaging Library image. The image should 135 | be in 1 bit mode and a size equal to the display size. 136 | 137 | :param Image img: The image to show 138 | """ 139 | 140 | imwidth, imheight = img.size 141 | if imwidth != self.columns or imheight != self.rows: 142 | raise ValueError( 143 | f"Image must be same dimensions as display ({self.columns}x{self.rows})." 144 | ) 145 | # Grab all the pixels from the image, faster than getpixel. 146 | pixels = img.convert("1").load() 147 | auto_write = self.auto_write 148 | self._auto_write = False 149 | # Iterate through the pixels 150 | for x in range(self.columns): # yes this double loop is slow, 151 | for y in range(self.rows): # but these displays are small! 152 | self.pixel(x, y, pixels[(x, y)]) 153 | self._auto_write = auto_write 154 | if self._auto_write: 155 | self.show() 156 | 157 | @property 158 | def columns(self) -> int: 159 | """Read-only property for number of columns""" 160 | return self._columns 161 | 162 | @property 163 | def rows(self) -> int: 164 | """Read-only property for number of rows""" 165 | return self._rows 166 | 167 | 168 | class Matrix16x8(Matrix8x8): 169 | """The matrix wing.""" 170 | 171 | _columns = 16 172 | 173 | def __init__( 174 | self, 175 | i2c: I2C, 176 | address: Union[int, List[int], Tuple[int, ...]] = 0x70, 177 | auto_write: bool = True, 178 | brightness: float = 1.0, 179 | ) -> None: 180 | super().__init__(i2c, address, auto_write, brightness) 181 | self._columns *= len(self.i2c_device) 182 | 183 | def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]: 184 | """Get or set the color of a given pixel. 185 | 186 | :param int x: The x coordinate of the pixel 187 | :param int y: The y coordinate of the pixel 188 | :param bool color: (Optional) The state to set the pixel 189 | :return: If ``color`` was not set, this returns the state of the pixel 190 | :rtype: bool 191 | """ 192 | 193 | if not 0 <= x <= self._columns - 1: 194 | return None 195 | if not 0 <= y <= self._rows - 1: 196 | return None 197 | while x >= 8: 198 | x -= 8 199 | y += 8 200 | 201 | return super()._pixel(y, x, color) 202 | 203 | 204 | class MatrixBackpack16x8(Matrix16x8): 205 | """A double matrix backpack.""" 206 | 207 | def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]: 208 | """Get or set the color of a given pixel. 209 | 210 | :param int x: The x coordinate of the pixel 211 | :param int y: The y coordinate of the pixel 212 | :param bool color: (Optional) The state to set the pixel 213 | :return: If ``color`` was not set, this returns the state of the pixel 214 | :rtype: bool 215 | """ 216 | 217 | if not 0 <= x <= self._columns - 1: 218 | return None 219 | if not 0 <= y <= self._rows - 1: 220 | return None 221 | return super()._pixel(x, y, color) 222 | 223 | 224 | class Matrix8x8x2(Matrix8x8): 225 | """A bi-color matrix.""" 226 | 227 | LED_OFF = 0 228 | LED_RED = 1 229 | LED_GREEN = 2 230 | LED_YELLOW = 3 231 | 232 | def pixel(self, x: int, y: int, color: Optional[int] = None) -> Optional[int]: 233 | """Get or set the color of a given pixel. 234 | 235 | :param int x: The x coordinate of the pixel 236 | :param int y: The y coordinate of the pixel 237 | :param int color: (Optional) The color to set the pixel 238 | :return: If ``color`` was not set, this returns the state of the pixel 239 | :rtype: int 240 | """ 241 | if not 0 <= x <= 7: 242 | return None 243 | if not 0 <= y <= 7: 244 | return None 245 | if color is not None: 246 | super()._pixel(y, x, (color >> 1) & 0x01) 247 | super()._pixel(y + 8, x, (color & 0x01)) 248 | else: 249 | return super()._pixel(y, x) << 1 | super()._pixel(y + 8, x) 250 | return None 251 | 252 | def fill(self, color: int) -> None: 253 | """Fill the whole display with the given color. 254 | 255 | :param int color: The color to fill the display 256 | """ 257 | 258 | fill1 = 0xFF if color & 0x01 else 0x00 259 | fill2 = 0xFF if color & 0x02 else 0x00 260 | for i in range(8): 261 | self._set_buffer(i * 2 + 1, fill1) 262 | self._set_buffer(i * 2, fill2) 263 | if self._auto_write: 264 | self.show() 265 | 266 | def image(self, img: Image) -> None: 267 | """Set buffer to value of Python Imaging Library image. The image should 268 | be a size equal to the display size. 269 | 270 | :param Image img: The image to show 271 | """ 272 | 273 | imwidth, imheight = img.size 274 | if imwidth != self.columns or imheight != self.rows: 275 | raise ValueError( 276 | f"Image must be same dimensions as display ({self.columns}x{self.rows})." 277 | ) 278 | # Grab all the pixels from the image, faster than getpixel. 279 | pixels = img.convert("RGB").load() 280 | auto_write = self.auto_write 281 | self._auto_write = False 282 | # Iterate through the pixels 283 | for x in range(self.columns): # yes this double loop is slow, 284 | for y in range(self.rows): # but these displays are small! 285 | if pixels[(x, y)] == (255, 0, 0): 286 | self.pixel(x, y, self.LED_RED) 287 | elif pixels[(x, y)] == (0, 255, 0): 288 | self.pixel(x, y, self.LED_GREEN) 289 | elif pixels[(x, y)] == (255, 255, 0): 290 | self.pixel(x, y, self.LED_YELLOW) 291 | else: 292 | # Unknown color, default to LED off. 293 | self.pixel(x, y, self.LED_OFF) 294 | self._auto_write = auto_write 295 | if self._auto_write: 296 | self.show() 297 | -------------------------------------------------------------------------------- /adafruit_ht16k33/segments.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Radomir Dopieralski 2016 for Adafruit Industries 2 | # SPDX-FileCopyrightText: Tony DiCola 2016 for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | """ 7 | adafruit_ht16k33.segments 8 | ========================= 9 | """ 10 | 11 | import time 12 | 13 | from adafruit_ht16k33.ht16k33 import HT16K33 14 | 15 | try: 16 | from typing import Dict, List, Optional, Tuple, Union 17 | 18 | from busio import I2C 19 | except ImportError: 20 | pass 21 | 22 | __version__ = "0.0.0+auto.0" 23 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git" 24 | 25 | # fmt: off 26 | CHARS = ( 27 | 0b00000000, 0b00000000, 28 | 0b01000000, 0b00000110, # ! 29 | 0b00000010, 0b00100000, # " 30 | 0b00010010, 0b11001110, # # 31 | 0b00010010, 0b11101101, # $ 32 | 0b00001100, 0b00100100, # % 33 | 0b00100011, 0b01011101, # & 34 | 0b00000100, 0b00000000, # ' 35 | 0b00100100, 0b00000000, # ( 36 | 0b00001001, 0b00000000, # ) 37 | 0b00111111, 0b11000000, # * 38 | 0b00010010, 0b11000000, # + 39 | 0b00001000, 0b00000000, # , 40 | 0b00000000, 0b11000000, # - 41 | 0b00000000, 0b00000000, # . 42 | 0b00001100, 0b00000000, # / 43 | 0b00001100, 0b00111111, # 0 44 | 0b00000000, 0b00000110, # 1 45 | 0b00000000, 0b11011011, # 2 46 | 0b00000000, 0b10001111, # 3 47 | 0b00000000, 0b11100110, # 4 48 | 0b00100000, 0b01101001, # 5 49 | 0b00000000, 0b11111101, # 6 50 | 0b00000000, 0b00000111, # 7 51 | 0b00000000, 0b11111111, # 8 52 | 0b00000000, 0b11101111, # 9 53 | 0b00010010, 0b00000000, # : 54 | 0b00001010, 0b00000000, # ; 55 | 0b00100100, 0b01000000, # < 56 | 0b00000000, 0b11001000, # = 57 | 0b00001001, 0b10000000, # > 58 | 0b01100000, 0b10100011, # ? 59 | 0b00000010, 0b10111011, # @ 60 | 0b00000000, 0b11110111, # A 61 | 0b00010010, 0b10001111, # B 62 | 0b00000000, 0b00111001, # C 63 | 0b00010010, 0b00001111, # D 64 | 0b00000000, 0b11111001, # E 65 | 0b00000000, 0b01110001, # F 66 | 0b00000000, 0b10111101, # G 67 | 0b00000000, 0b11110110, # H 68 | 0b00010010, 0b00000000, # I 69 | 0b00000000, 0b00011110, # J 70 | 0b00100100, 0b01110000, # K 71 | 0b00000000, 0b00111000, # L 72 | 0b00000101, 0b00110110, # M 73 | 0b00100001, 0b00110110, # N 74 | 0b00000000, 0b00111111, # O 75 | 0b00000000, 0b11110011, # P 76 | 0b00100000, 0b00111111, # Q 77 | 0b00100000, 0b11110011, # R 78 | 0b00000000, 0b11101101, # S 79 | 0b00010010, 0b00000001, # T 80 | 0b00000000, 0b00111110, # U 81 | 0b00001100, 0b00110000, # V 82 | 0b00101000, 0b00110110, # W 83 | 0b00101101, 0b00000000, # X 84 | 0b00010101, 0b00000000, # Y 85 | 0b00001100, 0b00001001, # Z 86 | 0b00000000, 0b00111001, # [ 87 | 0b00100001, 0b00000000, # \ 88 | 0b00000000, 0b00001111, # ] 89 | 0b00001100, 0b00000011, # ^ 90 | 0b00000000, 0b00001000, # _ 91 | 0b00000001, 0b00000000, # ` 92 | 0b00010000, 0b01011000, # a 93 | 0b00100000, 0b01111000, # b 94 | 0b00000000, 0b11011000, # c 95 | 0b00001000, 0b10001110, # d 96 | 0b00001000, 0b01011000, # e 97 | 0b00000000, 0b01110001, # f 98 | 0b00000100, 0b10001110, # g 99 | 0b00010000, 0b01110000, # h 100 | 0b00010000, 0b00000000, # i 101 | 0b00000000, 0b00001110, # j 102 | 0b00110110, 0b00000000, # k 103 | 0b00000000, 0b00110000, # l 104 | 0b00010000, 0b11010100, # m 105 | 0b00010000, 0b01010000, # n 106 | 0b00000000, 0b11011100, # o 107 | 0b00000001, 0b01110000, # p 108 | 0b00000100, 0b10000110, # q 109 | 0b00000000, 0b01010000, # r 110 | 0b00100000, 0b10001000, # s 111 | 0b00000000, 0b01111000, # t 112 | 0b00000000, 0b00011100, # u 113 | 0b00100000, 0b00000100, # v 114 | 0b00101000, 0b00010100, # w 115 | 0b00101000, 0b11000000, # x 116 | 0b00100000, 0b00001100, # y 117 | 0b00001000, 0b01001000, # z 118 | 0b00001001, 0b01001001, # { 119 | 0b00010010, 0b00000000, # | 120 | 0b00100100, 0b10001001, # } 121 | 0b00000101, 0b00100000, # ~ 122 | 0b00111111, 0b11111111, 123 | ) 124 | # fmt: on 125 | NUMBERS = ( 126 | 0x3F, # 0 127 | 0x06, # 1 128 | 0x5B, # 2 129 | 0x4F, # 3 130 | 0x66, # 4 131 | 0x6D, # 5 132 | 0x7D, # 6 133 | 0x07, # 7 134 | 0x7F, # 8 135 | 0x6F, # 9 136 | 0x77, # a 137 | 0x7C, # b 138 | 0x39, # C 139 | 0x5E, # d 140 | 0x79, # E 141 | 0x71, # F 142 | 0x3D, # G 143 | 0x76, # H 144 | 0x30, # I 145 | 0x1E, # J 146 | 0x40, # - 147 | 0x38, # L 148 | 0x40, # - 149 | 0x54, # n 150 | 0x5C, # o 151 | 0x73, # P 152 | 0x67, # q 153 | 0x50, # R 154 | 0x6D, # S 155 | 0x78, # t 156 | 0x3E, # U 157 | 0x1C, # v 158 | 0x40, # - 159 | 0x40, # - 160 | 0x6E, # y 161 | 0x40, # - 162 | 0x40, # - 163 | ) 164 | 165 | 166 | class Seg14x4(HT16K33): 167 | """Alpha-Numeric 14-segment display. 168 | 169 | :param I2C i2c: The I2C bus object 170 | :param int|list|tuple address: The I2C address(es) for the display. Can be a tuple or 171 | list for multiple displays. 172 | :param bool auto_write: True if the display should immediately change when set. If False, 173 | `show` must be called explicitly. 174 | :param int chars_per_display: A number between 1-8 represesenting the number of characters 175 | on each display. 176 | """ 177 | 178 | def __init__( 179 | self, 180 | i2c: I2C, 181 | address: Union[int, List[int], Tuple[int, ...]] = 0x70, 182 | auto_write: bool = True, 183 | chars_per_display: int = 4, 184 | ) -> None: 185 | super().__init__(i2c, address, auto_write) 186 | if not 1 <= chars_per_display <= 8: 187 | raise ValueError("Input overflow - The HT16K33 only supports up 1-8 characters!") 188 | 189 | self._chars = chars_per_display * len(self.i2c_device) 190 | self._bytes_per_char = 2 191 | self._last_nb_scroll_time = -1 192 | self._nb_scroll_text = None 193 | self._nb_scroll_index = -1 194 | self._nb_prev_char_is_dot = False 195 | 196 | def print(self, value: Union[str, float], decimal: int = 0) -> None: 197 | """Print the value to the display. 198 | 199 | :param str|float value: The value to print 200 | :param int decimal: The number of decimal places for a floating point 201 | number if decimal is greater than zero, or the input number is an 202 | integer if decimal is zero. 203 | """ 204 | 205 | if isinstance(value, str): 206 | self._text(value) 207 | elif isinstance(value, (int, float)): 208 | self._number(value, decimal) 209 | else: 210 | raise ValueError(f"Unsupported display value type: {type(value)}") 211 | if self._auto_write: 212 | self.show() 213 | 214 | def print_hex(self, value: Union[int, str]) -> None: 215 | """Print the value as a hexidecimal string to the display. 216 | 217 | :param int|str value: The number to print 218 | """ 219 | 220 | if isinstance(value, int): 221 | self.print(f"{value:X}") 222 | else: 223 | self.print(value) 224 | 225 | def __setitem__(self, key: int, value: str) -> None: 226 | self._put(value, key) 227 | if self._auto_write: 228 | self.show() 229 | 230 | def scroll(self, count: int = 1) -> None: 231 | """Scroll the display by specified number of places. 232 | 233 | :param int count: The number of places to scroll 234 | """ 235 | 236 | if count >= 0: 237 | offset = 0 238 | else: 239 | offset = 2 240 | for i in range((self._chars - 1) * 2): 241 | self._set_buffer( 242 | self._adjusted_index(i + offset), 243 | self._get_buffer(self._adjusted_index(i + 2 * count)), 244 | ) 245 | 246 | def _put(self, char: str, index: int = 0) -> None: 247 | """Put a character at the specified place.""" 248 | if not 0 <= index < self._chars: 249 | return 250 | if not 32 <= ord(char) <= 127: 251 | return 252 | if char == ".": 253 | self._set_buffer( 254 | self._adjusted_index(index * 2 + 1), 255 | self._get_buffer(self._adjusted_index(index * 2 + 1)) | 0b01000000, 256 | ) 257 | return 258 | character = ord(char) * 2 - 64 259 | self._set_buffer(self._adjusted_index(index * 2), CHARS[1 + character]) 260 | self._set_buffer(self._adjusted_index(index * 2 + 1), CHARS[character]) 261 | 262 | def _push(self, char: str) -> None: 263 | """Scroll the display and add a character at the end.""" 264 | if ( 265 | char != "." 266 | or self._get_buffer(self._char_buffer_index(self._chars - 1) + 1) & 0b01000000 267 | ): 268 | self.scroll() 269 | self._put(" ", self._chars - 1) 270 | self._put(char, self._chars - 1) 271 | 272 | def _text(self, text: str) -> None: 273 | """Display the specified text.""" 274 | for character in text: 275 | self._push(character) 276 | 277 | def _number(self, number: float, decimal: int = 0) -> str: 278 | """ 279 | Display a floating point or integer number on the Adafruit HT16K33 based displays 280 | 281 | :param float number: The floating point or integer number to be displayed, which must be 282 | in the range 0 (zero) to 9999 for integers and floating point or integer numbers 283 | and between 0.0 and 999.0 or 99.00 or 9.000 for floating point numbers. 284 | :param int decimal: The number of decimal places for a floating point number if decimal 285 | is greater than zero, or the input number is an integer if decimal is zero. 286 | :return: The output text string to be displayed 287 | """ 288 | 289 | auto_write = self._auto_write 290 | self._auto_write = False 291 | stnum = str(number) 292 | dot = stnum.find(".") 293 | 294 | if (len(stnum) > self._chars + 1) or ((len(stnum) > self._chars) and (dot < 0)): 295 | self._auto_write = auto_write 296 | raise ValueError(f"Input overflow - {number} is too large for the display!") 297 | 298 | if dot < 0: 299 | # No decimal point (Integer) 300 | places = len(stnum) 301 | else: 302 | places = len(stnum[:dot]) 303 | 304 | if places <= 0 < decimal: 305 | self.fill(False) 306 | places = self._chars 307 | 308 | if "." in stnum: 309 | places += 1 310 | 311 | # Set decimal places, if number of decimal places is specified (decimal > 0) 312 | txt = stnum 313 | if places > 0 < decimal < len(stnum[places:]) and dot > 0: 314 | txt = stnum[: dot + decimal + 1] 315 | elif places > 0: 316 | txt = stnum[:places] 317 | 318 | if len(txt) > self._chars + 1: 319 | self._auto_write = auto_write 320 | raise ValueError(f"Output string ('{txt}') is too long!") 321 | 322 | self._text(txt) 323 | self._auto_write = auto_write 324 | 325 | return txt 326 | 327 | def _adjusted_index(self, index: int) -> int: 328 | # Determine which part of the buffer to use and adjust index 329 | offset = (index // self._bytes_per_buffer()) * self._buffer_size 330 | return offset + index % self._bytes_per_buffer() 331 | 332 | def _chars_per_buffer(self) -> int: 333 | return self._chars // len(self.i2c_device) 334 | 335 | def _bytes_per_buffer(self) -> int: 336 | return self._bytes_per_char * self._chars_per_buffer() 337 | 338 | def _char_buffer_index(self, char_pos: int) -> int: 339 | offset = (char_pos // self._chars_per_buffer()) * self._buffer_size 340 | return offset + (char_pos % self._chars_per_buffer()) * self._bytes_per_char 341 | 342 | def set_digit_raw(self, index: int, bitmask: Union[int, List[int], Tuple[int, int]]) -> None: 343 | """Set digit at position to raw bitmask value. Position should be a value 344 | of 0 to 3 with 0 being the left most character on the display. 345 | 346 | :param int index: The index of the display to set 347 | :param bitmask: A 2 byte number corresponding to the segments to set 348 | :type bitmask: int, or a list/tuple of int 349 | """ 350 | if not isinstance(index, int) or not 0 <= index <= self._chars - 1: 351 | raise ValueError(f"Index value must be an integer in the range: 0-{self._chars - 1}") 352 | 353 | if isinstance(bitmask, (tuple, list)): 354 | bitmask = ((bitmask[0] & 0xFF) << 8) | (bitmask[1] & 0xFF) 355 | 356 | # Use only the valid potion of bitmask 357 | bitmask &= 0xFFFF 358 | 359 | # Set the digit bitmask value at the appropriate position. 360 | self._set_buffer(self._adjusted_index(index * 2), bitmask & 0xFF) 361 | self._set_buffer(self._adjusted_index(index * 2 + 1), (bitmask >> 8) & 0xFF) 362 | 363 | if self._auto_write: 364 | self.show() 365 | 366 | def non_blocking_marquee( 367 | self, 368 | text: str, 369 | delay: float = 0.25, 370 | loop: bool = True, 371 | space_between: bool = False, 372 | ) -> bool: 373 | """ 374 | Scroll the text at the specified delay between characters. Must be called 375 | repeatedly from main loop faster than delay time. 376 | 377 | :param str text: The text to display 378 | :param float delay: (optional) The delay in seconds to pause before scrolling 379 | to the next character (default=0.25) 380 | :param bool loop: (optional) Whether to endlessly loop the text (default=True) 381 | :param bool space_between: (optional) Whether to seperate the end and beginning of 382 | the text with a space. (default=False) 383 | """ 384 | if isinstance(text, str): 385 | now = time.monotonic() 386 | # if text is the same 387 | if text == self._nb_scroll_text: 388 | # if we delayed long enough, and it's time to scroll 389 | if now >= self._last_nb_scroll_time + delay: 390 | # if there are chars left in the text 391 | if self._nb_scroll_index + 1 < len(text): 392 | self._nb_scroll_index += 1 393 | 394 | _character = text[self._nb_scroll_index] 395 | 396 | if _character != "." or self._nb_prev_char_is_dot: 397 | self._last_nb_scroll_time = now 398 | 399 | self.print(text[self._nb_scroll_index]) 400 | self._nb_prev_char_is_dot = text[self._nb_scroll_index] == "." 401 | elif loop: 402 | self._nb_scroll_index = -1 403 | if space_between: 404 | self._last_nb_scroll_time = now 405 | self.print(" ") 406 | else: 407 | return True 408 | else: 409 | # different text 410 | self._nb_scroll_index = 0 411 | self.fill(False) 412 | self._nb_scroll_text = text 413 | self._last_nb_scroll_time = now 414 | self.print(text[0]) 415 | 416 | return False 417 | 418 | def marquee( 419 | self, text: str, delay: float = 0.25, loop: bool = True, space_between=False 420 | ) -> None: 421 | """ 422 | Automatically scroll the text at the specified delay between characters 423 | 424 | :param str text: The text to display 425 | :param float delay: (optional) The delay in seconds to pause before scrolling 426 | to the next character (default=0.25) 427 | :param bool loop: (optional) Whether to endlessly loop the text (default=True) 428 | :param bool space_between: (optional) Whether to seperate the end and beginning of 429 | the text with a space. (default=False) 430 | """ 431 | if isinstance(text, str): 432 | self.fill(False) 433 | while True: 434 | if self.non_blocking_marquee( 435 | text=text, delay=delay, loop=loop, space_between=space_between 436 | ): 437 | return 438 | 439 | 440 | class _AbstractSeg7x4(Seg14x4): 441 | POSITIONS = (0, 2, 6, 8) # The positions of characters. 442 | 443 | def __init__( 444 | self, 445 | i2c: I2C, 446 | address: Union[int, List[int], Tuple[int, ...]] = 0x70, 447 | auto_write: bool = True, 448 | char_dict: Optional[Dict[str, int]] = None, 449 | chars_per_display: int = 4, 450 | ) -> None: 451 | super().__init__(i2c, address, auto_write, chars_per_display) 452 | self._chardict = char_dict 453 | self._bytes_per_char = 1 454 | 455 | def _adjusted_index(self, index: int) -> int: 456 | # Determine which part of the buffer to use and adjust index 457 | offset = (index // self._bytes_per_buffer()) * self._buffer_size 458 | return offset + self.POSITIONS[index % self._bytes_per_buffer()] 459 | 460 | def scroll(self, count: int = 1) -> None: 461 | """Scroll the display by specified number of places. 462 | 463 | :param int count: The number of places to scroll 464 | """ 465 | 466 | if count >= 0: 467 | offset = 0 468 | else: 469 | offset = 1 470 | for i in range(self._chars - 1): 471 | self._set_buffer( 472 | self._adjusted_index(i + offset), 473 | self._get_buffer(self._adjusted_index(i + count)), 474 | ) 475 | 476 | def _push(self, char: str) -> None: 477 | """Scroll the display and add a character at the end.""" 478 | if char in ":;": 479 | self._put(char) 480 | else: 481 | if char != "." or self._get_buffer(self._adjusted_index(self._chars - 1)) & 0b10000000: 482 | self.scroll() 483 | self._put(" ", self._chars - 1) 484 | self._put(char, self._chars - 1) 485 | 486 | def _put(self, char: str, index: int = 0) -> None: 487 | """Put a character at the specified place.""" 488 | if not 0 <= index < self._chars: 489 | return 490 | index = self._adjusted_index(index) 491 | if self._chardict and char in self._chardict: 492 | self._set_buffer(index, self._chardict[char]) 493 | return 494 | char = char.lower() 495 | if char == ".": 496 | self._set_buffer(index, self._get_buffer(index) | 0b10000000) 497 | return 498 | if char in "abcdefghijklmnopqrstuvwxy": 499 | character = ord(char) - 97 + 10 500 | elif char == "-": 501 | character = 36 502 | elif char in "0123456789": 503 | character = ord(char) - 48 504 | elif char == " ": 505 | self._set_buffer(index, 0x00) 506 | return 507 | elif char == ":": 508 | self._set_buffer(4, 0x02) 509 | return 510 | elif char == ";": 511 | self._set_buffer(4, 0x00) 512 | return 513 | elif char in "lL": 514 | self._set_buffer(index, 0b00111000) 515 | return 516 | elif char in "oO": 517 | self._set_buffer(index, 0b00111111) 518 | return 519 | else: 520 | return 521 | self._set_buffer(index, NUMBERS[character]) 522 | 523 | def set_digit_raw(self, index: int, bitmask: int) -> None: 524 | """Set digit at position to raw bitmask value. Position should be a value 525 | of 0 to 3 with 0 being the left most digit on the display. 526 | 527 | :param int index: The index of the display to set 528 | :param int bitmask: A single byte number corresponding to the segments to set 529 | """ 530 | 531 | if not isinstance(index, int) or not 0 <= index < self._chars: 532 | raise ValueError(f"Index value must be an integer in the range: 0-{self._chars - 1}") 533 | 534 | # Set the digit bitmask value at the appropriate position. 535 | self._set_buffer(self._adjusted_index(index), bitmask & 0xFF) 536 | 537 | if self._auto_write: 538 | self.show() 539 | 540 | 541 | class Seg7x4(_AbstractSeg7x4): 542 | """Numeric 7-segment display. It has the same methods as the alphanumeric display, but only 543 | supports displaying a limited set of characters. 544 | 545 | :param I2C i2c: The I2C bus object 546 | :param int|list|tuple address: The I2C address for the display. Can be a tuple or list for 547 | multiple displays. 548 | :param bool auto_write: True if the display should immediately change when set. If False, 549 | `show` must be called explicitly. 550 | :param dict char_dict: An optional dictionary mapping strings to bit settings integers used 551 | for defining how to display custom letters 552 | :param int chars_per_display: A number between 1-8 represesenting the number of characters 553 | on each display. 554 | """ 555 | 556 | def __init__( 557 | self, 558 | i2c: I2C, 559 | address: Union[int, List[int], Tuple[int, ...]] = 0x70, 560 | auto_write: bool = True, 561 | char_dict: Optional[Dict[str, int]] = None, 562 | chars_per_display: int = 4, 563 | ) -> None: 564 | super().__init__(i2c, address, auto_write, char_dict, chars_per_display) 565 | # Use colon for controling two-dots indicator at the center (index 0) 566 | self._colon = Colon(self) 567 | 568 | @property 569 | def colon(self) -> bool: 570 | """Simplified colon accessor""" 571 | return self._colon[0] 572 | 573 | @colon.setter 574 | def colon(self, turn_on: bool) -> None: 575 | self._colon[0] = turn_on 576 | 577 | 578 | class BigSeg7x4(_AbstractSeg7x4): 579 | """Numeric 7-segment display. It has the same methods as the alphanumeric display, but only 580 | supports displaying a limited set of characters. 581 | 582 | :param I2C i2c: The I2C bus object 583 | :param int|list|tuple address: The I2C address(es) for the display 584 | :param bool auto_write: True if the display should immediately change when set. If False, 585 | `show` must be called explicitly. 586 | :param dict char_dict: An optional dictionary mapping strings to bit settings integers used 587 | for defining how to display custom letters 588 | """ 589 | 590 | def __init__( 591 | self, 592 | i2c: I2C, 593 | address: Union[int, List[int], Tuple[int, ...]] = 0x70, 594 | auto_write: bool = True, 595 | char_dict: Optional[Dict[str, int]] = None, 596 | ) -> None: 597 | super().__init__(i2c, address, auto_write, char_dict) 598 | # Use colon for controling two-dots indicator at the center (index 0) 599 | # or the two-dots indicators at the left (index 1) 600 | self.colons = Colon(self, 2) 601 | 602 | def _setindicator(self, index: int, value: bool) -> None: 603 | """Set side LEDs (dots) 604 | Index is as follow : 605 | * 0 : two dots at the center 606 | * 1 : top-left dot 607 | * 2 : bottom-left dot 608 | * 3 : right dot (also ampm indicator) 609 | """ 610 | bitmask = 1 << (index + 1) 611 | current = self._get_buffer(0x04) 612 | if value: 613 | self._set_buffer(0x04, current | bitmask) 614 | else: 615 | self._set_buffer(0x04, current & ~bitmask) 616 | if self._auto_write: 617 | self.show() 618 | 619 | def _getindicator(self, index: int) -> int: 620 | """Get side LEDs (dots) 621 | See setindicator() for indexes 622 | """ 623 | bitmask = 1 << (index + 1) 624 | return self._get_buffer(0x04) & bitmask 625 | 626 | @property 627 | def top_left_dot(self) -> bool: 628 | """The top-left dot indicator.""" 629 | return bool(self._getindicator(1)) 630 | 631 | @top_left_dot.setter 632 | def top_left_dot(self, value: bool) -> None: 633 | self._setindicator(1, value) 634 | 635 | @property 636 | def bottom_left_dot(self) -> bool: 637 | """The bottom-left dot indicator.""" 638 | return bool(self._getindicator(2)) 639 | 640 | @bottom_left_dot.setter 641 | def bottom_left_dot(self, value: bool) -> None: 642 | self._setindicator(2, value) 643 | 644 | @property 645 | def ampm(self) -> bool: 646 | """The AM/PM indicator.""" 647 | return bool(self._getindicator(3)) 648 | 649 | @ampm.setter 650 | def ampm(self, value: bool) -> None: 651 | self._setindicator(3, value) 652 | 653 | 654 | class Colon: 655 | """Helper class for controlling the colons. Not intended for direct use.""" 656 | 657 | MASKS = (0x02, 0x0C) 658 | 659 | def __init__(self, disp: _AbstractSeg7x4, num_of_colons: int = 1) -> None: 660 | self._disp = disp 661 | self._num_of_colons = num_of_colons 662 | 663 | def __setitem__(self, key: int, value: bool) -> None: 664 | if key > self._num_of_colons - 1: 665 | raise ValueError("Trying to set a non-existent colon.") 666 | current = self._disp._get_buffer(0x04) 667 | if value: 668 | self._disp._set_buffer(0x04, current | self.MASKS[key]) 669 | else: 670 | self._disp._set_buffer(0x04, current & ~self.MASKS[key]) 671 | if self._disp.auto_write: 672 | self._disp.show() 673 | 674 | def __getitem__(self, key: int) -> bool: 675 | if key > self._num_of_colons - 1: 676 | raise ValueError("Trying to access a non-existent colon.") 677 | return bool(self._disp._get_buffer(0x04) & self.MASKS[key]) 678 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_HT16K33/43817d123b003a1fb4cea34c085ef6f5816781e8/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/_static/favicon.ico.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries 2 | 3 | SPDX-License-Identifier: CC-BY-4.0 4 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | 2 | .. If you created a package, create one automodule per module in the package. 3 | 4 | API Reference 5 | ############# 6 | 7 | .. automodule:: adafruit_ht16k33.ht16k33 8 | :members: 9 | 10 | .. automodule:: adafruit_ht16k33.bargraph 11 | :members: 12 | 13 | .. automodule:: adafruit_ht16k33.matrix 14 | :members: 15 | 16 | .. automodule:: adafruit_ht16k33.segments 17 | :members: 18 | 19 | .. automodule:: adafruit_ht16k33.animations 20 | :members: 21 | -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | import datetime 6 | import os 7 | import sys 8 | 9 | sys.path.insert(0, os.path.abspath("..")) 10 | 11 | # -- General configuration ------------------------------------------------ 12 | 13 | # Add any Sphinx extension module names here, as strings. They can be 14 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 15 | # ones. 16 | extensions = [ 17 | "sphinx.ext.autodoc", 18 | "sphinxcontrib.jquery", 19 | "sphinx.ext.intersphinx", 20 | "sphinx.ext.viewcode", 21 | ] 22 | 23 | # Uncomment the below if you use native CircuitPython modules such as 24 | # digitalio, micropython and busio. List the modules you use. Without it, the 25 | # autodoc module docs will fail to generate with a warning. 26 | # autodoc_mock_imports = ["adafruit_bus_device", "micropython"] 27 | 28 | intersphinx_mapping = { 29 | "python": ("https://docs.python.org/3", None), 30 | "BusDevice": ( 31 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 32 | None, 33 | ), 34 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 35 | } 36 | 37 | # Add any paths that contain templates here, relative to this directory. 38 | templates_path = ["_templates"] 39 | 40 | source_suffix = ".rst" 41 | 42 | # The master toctree document. 43 | master_doc = "index" 44 | 45 | # General information about the project. 46 | project = "Adafruit HT16K33 Library" 47 | creation_year = "2016" 48 | current_year = str(datetime.datetime.now().year) 49 | year_duration = ( 50 | current_year if current_year == creation_year else creation_year + " - " + current_year 51 | ) 52 | copyright = year_duration + " Radomir Dopieralski" 53 | author = "Radomir Dopieralski" 54 | 55 | # The version info for the project you're documenting, acts as replacement for 56 | # |version| and |release|, also used in various other places throughout the 57 | # built documents. 58 | # 59 | # The short X.Y version. 60 | version = "1.0" 61 | # The full version, including alpha/beta/rc tags. 62 | release = "1.0" 63 | 64 | # The language for content autogenerated by Sphinx. Refer to documentation 65 | # for a list of supported languages. 66 | # 67 | # This is also used if you do content translation via gettext catalogs. 68 | # Usually you set "language" from the command line for these cases. 69 | language = "en" 70 | 71 | # List of patterns, relative to source directory, that match files and 72 | # directories to ignore when looking for source files. 73 | # This patterns also effect to html_static_path and html_extra_path 74 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 75 | 76 | # The reST default role (used for this markup: `text`) to use for all 77 | # documents. 78 | # 79 | default_role = "any" 80 | 81 | # If true, '()' will be appended to :func: etc. cross-reference text. 82 | # 83 | add_function_parentheses = True 84 | 85 | # The name of the Pygments (syntax highlighting) style to use. 86 | pygments_style = "sphinx" 87 | 88 | # If true, `todo` and `todoList` produce output, else they produce nothing. 89 | todo_include_todos = False 90 | 91 | # If this is True, todo emits a warning for each TODO entries. The default is False. 92 | todo_emit_warnings = True 93 | 94 | 95 | # -- Options for HTML output ---------------------------------------------- 96 | 97 | # The theme to use for HTML and HTML Help pages. See the documentation for 98 | # a list of builtin themes. 99 | # 100 | import sphinx_rtd_theme 101 | 102 | html_theme = "sphinx_rtd_theme" 103 | 104 | # Add any paths that contain custom static files (such as style sheets) here, 105 | # relative to this directory. They are copied after the builtin static files, 106 | # so a file named "default.css" will overwrite the builtin "default.css". 107 | html_static_path = ["_static"] 108 | 109 | # The name of an image file (relative to this directory) to use as a favicon of 110 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 111 | # pixels large. 112 | # 113 | html_favicon = "_static/favicon.ico" 114 | 115 | # Output file base name for HTML help builder. 116 | htmlhelp_basename = "AdafruitHT16K33Librarydoc" 117 | 118 | # -- Options for LaTeX output --------------------------------------------- 119 | 120 | latex_elements = { 121 | # The paper size ('letterpaper' or 'a4paper'). 122 | # 123 | # 'papersize': 'letterpaper', 124 | # The font size ('10pt', '11pt' or '12pt'). 125 | # 126 | # 'pointsize': '10pt', 127 | # Additional stuff for the LaTeX preamble. 128 | # 129 | # 'preamble': '', 130 | # Latex figure (float) alignment 131 | # 132 | # 'figure_align': 'htbp', 133 | } 134 | 135 | # Grouping the document tree into LaTeX files. List of tuples 136 | # (source start file, target name, title, 137 | # author, documentclass [howto, manual, or own class]). 138 | latex_documents = [ 139 | ( 140 | master_doc, 141 | "AdafruitHT16K33Library.tex", 142 | "Adafruit HT16K33 Library Documentation", 143 | author, 144 | "manual", 145 | ), 146 | ] 147 | 148 | # -- Options for manual page output --------------------------------------- 149 | 150 | # One entry per manual page. List of tuples 151 | # (source start file, name, description, authors, manual section). 152 | man_pages = [ 153 | ( 154 | master_doc, 155 | "adafruitHT16K33library", 156 | "Adafruit HT16K33 Library Documentation", 157 | [author], 158 | 1, 159 | ) 160 | ] 161 | 162 | # -- Options for Texinfo output ------------------------------------------- 163 | 164 | # Grouping the document tree into Texinfo files. List of tuples 165 | # (source start file, target name, title, author, 166 | # dir menu entry, description, category) 167 | texinfo_documents = [ 168 | ( 169 | master_doc, 170 | "AdafruitHT16K33Library", 171 | "Adafruit HT16K33 Library Documentation", 172 | author, 173 | "AdafruitHT16K33Library", 174 | "One line description of project.", 175 | "Miscellaneous", 176 | ), 177 | ] 178 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/ht16k33_matrix_simpletest.py 7 | :caption: examples/ht16k33_matrix_simpletest.py 8 | :linenos: 9 | 10 | .. literalinclude:: ../examples/ht16k33_segments_simpletest.py 11 | :caption: examples/ht16k33_segments_simpletest.py 12 | :linenos: 13 | 14 | .. literalinclude:: ../examples/ht16k33_bicolor24_simpletest.py 15 | :caption: examples/ht16k33_bicolor24_simpletest.py 16 | :linenos: 17 | 18 | .. literalinclude:: ../examples/ht16k33_matrix_pillow_image.py 19 | :caption: examples/ht16k33_matrix_pillow_image.py 20 | :linenos: 21 | 22 | .. literalinclude:: ../examples/ht16k33_animation_demo.py 23 | :caption: examples/ht16k33_animation_demo.py 24 | :linenos: 25 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Table of Contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | :hidden: 9 | 10 | self 11 | 12 | .. toctree:: 13 | :caption: Examples 14 | 15 | examples 16 | 17 | .. toctree:: 18 | :caption: API Reference 19 | :maxdepth: 3 20 | 21 | api 22 | 23 | .. toctree:: 24 | :caption: Tutorials 25 | 26 | .. toctree:: 27 | :caption: Related Products 28 | 29 | Adafruit HT16K33 Products 30 | 31 | .. toctree:: 32 | :caption: Other Links 33 | 34 | Download from GitHub 35 | Download Library Bundle 36 | CircuitPython Reference Documentation 37 | CircuitPython Support Forum 38 | Discord Chat 39 | Adafruit Learning System 40 | Adafruit Blog 41 | Adafruit Store 42 | 43 | Indices and tables 44 | ================== 45 | 46 | * :ref:`genindex` 47 | * :ref:`modindex` 48 | * :ref:`search` 49 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | sphinx 6 | sphinxcontrib-jquery 7 | sphinx-rtd-theme 8 | -------------------------------------------------------------------------------- /examples/ht16k33_animation_demo.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | """ 5 | Test script for display animations on an HT16K33 with alphanumeric display 6 | 7 | The display must be initialized with auto_write=False. 8 | """ 9 | 10 | from time import sleep 11 | 12 | import board 13 | 14 | from adafruit_ht16k33.animations import Animation 15 | from adafruit_ht16k33.segments import Seg14x4 16 | 17 | # Initialize the I2C bus 18 | i2c = board.I2C() # uses board.SCL and board.SDA 19 | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller 20 | display = Seg14x4(i2c, auto_write=False) 21 | # Brightness of the display (0.0 to 1.0) 22 | display.brightness = 0.3 23 | 24 | ani = Animation(display) 25 | 26 | try: 27 | text = "Init" 28 | 29 | display.fill(1) 30 | display.show() 31 | sleep(1) 32 | display.fill(0) 33 | display.show() 34 | 35 | display.print(text) 36 | display.show() 37 | sleep(2) 38 | display.fill(0) 39 | display.show() 40 | sleep(1) 41 | 42 | ani.count_down() 43 | sleep(0.2) 44 | 45 | text = "Go!!" 46 | 47 | display.print(text) 48 | display.show() 49 | sleep(1.5) 50 | display.fill(0) 51 | display.show() 52 | sleep(0.5) 53 | print() 54 | 55 | while True: 56 | # Arrow 57 | print("Arrow") 58 | ani.animate([0, 1, 2], [192], 0.1) 59 | ani.animate([3], [2368], 0.1) 60 | sleep(1.0) 61 | display.fill(0) 62 | sleep(1.0) 63 | 64 | # Flying 65 | print("Flying") 66 | cyc = 0 67 | 68 | while cyc < 5: 69 | ani.animate([0], [1280, 192, 10240, 192], 0.2) 70 | 71 | cyc += 1 72 | 73 | ani.animate([0], [0]) 74 | sleep(1.0) 75 | display.fill(0) 76 | sleep(1.0) 77 | 78 | # Chase forward and reverse. 79 | print("Chase forward and reverse") 80 | ani.chase_forward_and_reverse(0.01, 5) 81 | sleep(1.0) 82 | display.fill(0) 83 | sleep(1.0) 84 | 85 | # Testing writing to more than one segment simultaneously 86 | print("Prelude to Spinners") 87 | ani.prelude_to_spinners(0.1, 5) 88 | sleep(1.0) 89 | display.fill(0) 90 | display.show() 91 | sleep(1.0) 92 | 93 | print("Spinners") 94 | ani.spinners(0.1, 20) 95 | sleep(1.0) 96 | display.fill(0) 97 | display.show() 98 | sleep(1.0) 99 | 100 | print("Enclosed Spinners") 101 | ani.enclosed_spinners(0.1, 20) 102 | sleep(1.0) 103 | display.fill(0) 104 | display.show() 105 | sleep(1.0) 106 | 107 | print() 108 | except KeyboardInterrupt: 109 | display.fill(0) 110 | display.show() 111 | -------------------------------------------------------------------------------- /examples/ht16k33_bicolor24_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Basic example of using the Bi-color 24 segment bargraph display. 5 | # This example and library is meant to work with Adafruit CircuitPython API. 6 | # Author: Carter Nelson 7 | # License: Public Domain 8 | 9 | import time 10 | 11 | # Import board related modules 12 | import board 13 | import busio 14 | 15 | # Import the Bicolor24 driver from the HT16K33 module 16 | from adafruit_ht16k33.bargraph import Bicolor24 17 | 18 | # Create the I2C interface 19 | i2c = busio.I2C(board.SCL, board.SDA) 20 | 21 | # Create the LED bargraph class. 22 | bc24 = Bicolor24(i2c) 23 | 24 | # Set individual segments of bargraph 25 | bc24[0] = bc24.LED_RED 26 | bc24[1] = bc24.LED_GREEN 27 | bc24[2] = bc24.LED_YELLOW 28 | 29 | time.sleep(2) 30 | 31 | # Turn them all off 32 | bc24.fill(bc24.LED_OFF) 33 | 34 | # Turn them on in a loop 35 | for i in range(24): 36 | bc24[i] = bc24.LED_RED 37 | time.sleep(0.1) 38 | bc24[i] = bc24.LED_OFF 39 | 40 | time.sleep(1) 41 | 42 | # Fill the entrire bargraph 43 | bc24.fill(bc24.LED_GREEN) 44 | -------------------------------------------------------------------------------- /examples/ht16k33_matrix_multi_display.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Basic example of clearing and drawing pixels on two LED matrix displays. 5 | # This example and library is meant to work with Adafruit CircuitPython API. 6 | # Author: Melissa LeBlanc-Williams 7 | # License: Public Domain 8 | 9 | # Import all board pins. 10 | import time 11 | 12 | import board 13 | import busio 14 | 15 | # Import the HT16K33 LED matrix module. 16 | from adafruit_ht16k33 import matrix 17 | 18 | # Create the I2C interface. 19 | i2c = busio.I2C(board.SCL, board.SDA) 20 | 21 | # Create the matrix class. 22 | # This creates a 16x8 matrix with multiple displays: 23 | matrix = matrix.Matrix16x8(i2c, address=(0x70, 0x71)) 24 | 25 | # Clear the matrix. 26 | matrix.fill(0) 27 | 28 | # Set a pixel in the origin 0, 0 position. 29 | matrix[0, 0] = 1 30 | # Set a pixel in the middle 8, 4 position. 31 | matrix[8, 4] = 1 32 | # Set a pixel in the opposite 15, 7 position. 33 | matrix[15, 7] = 1 34 | 35 | # Set pixels in the second display. 36 | matrix[16, 7] = 1 37 | matrix[24, 4] = 1 38 | matrix[31, 0] = 1 39 | 40 | time.sleep(2) 41 | 42 | # Draw a Smiley Face 43 | matrix.fill(0) 44 | 45 | for row in range(2, 6): 46 | matrix[row, 0] = 1 47 | matrix[row, 7] = 1 48 | 49 | for column in range(2, 6): 50 | matrix[0, column] = 1 51 | matrix[7, column] = 1 52 | 53 | matrix[1, 1] = 1 54 | matrix[1, 6] = 1 55 | matrix[6, 1] = 1 56 | matrix[6, 6] = 1 57 | matrix[2, 5] = 1 58 | matrix[5, 5] = 1 59 | matrix[2, 3] = 1 60 | matrix[5, 3] = 1 61 | matrix[3, 2] = 1 62 | matrix[4, 2] = 1 63 | 64 | # Move the Smiley Face Around 65 | while True: 66 | for frame in range(0, 24): 67 | matrix.shift_right(True) 68 | time.sleep(0.05) 69 | for frame in range(0, 8): 70 | matrix.shift_down(True) 71 | time.sleep(0.05) 72 | for frame in range(0, 24): 73 | matrix.shift_left(True) 74 | time.sleep(0.05) 75 | for frame in range(0, 8): 76 | matrix.shift_up(True) 77 | time.sleep(0.05) 78 | -------------------------------------------------------------------------------- /examples/ht16k33_matrix_pillow_image.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Basic example of drawing an image 5 | # This example and library is meant to work with Adafruit CircuitPython API. 6 | # 7 | # This example is for use on (Linux) computers that are using CPython with 8 | # Adafruit Blinka to support CircuitPython libraries. CircuitPython does 9 | # not support PIL/pillow (python imaging library)! 10 | # 11 | # Author: Melissa LeBlanc-Williams 12 | # License: Public Domain 13 | 14 | # Import all board pins. 15 | import board 16 | import busio 17 | from PIL import Image 18 | 19 | # Import the HT16K33 LED matrix module. 20 | from adafruit_ht16k33 import matrix 21 | 22 | # Create the I2C interface. 23 | i2c = busio.I2C(board.SCL, board.SDA) 24 | 25 | # Create the matrix class. 26 | # This creates a 16x8 matrix: 27 | mtrx = matrix.Matrix16x8(i2c) 28 | # Or this creates a 16x8 matrix backpack: 29 | # mtrx = matrix.MatrixBackpack16x8(i2c) 30 | # Or this creates a 8x8 matrix: 31 | # mtrx = matrix.Matrix8x8(i2c) 32 | # Or this creates a 8x8 bicolor matrix: 33 | # mtrx = matrix.Matrix8x8x2(i2c) 34 | # Finally you can optionally specify a custom I2C address of the HT16k33 like: 35 | # mtrx = matrix.Matrix16x8(i2c, address=0x70) 36 | 37 | if isinstance(mtrx, matrix.Matrix8x8x2): 38 | image = Image.open("squares-color.png") 39 | elif isinstance(mtrx, matrix.Matrix16x8): 40 | image = Image.open("squares-mono-16x8.png") 41 | else: 42 | image = Image.open("squares-mono-8x8.png") 43 | 44 | # Clear the matrix 45 | mtrx.fill(0) 46 | mtrx.image(image) 47 | -------------------------------------------------------------------------------- /examples/ht16k33_matrix_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Basic example of clearing and drawing a pixel on a LED matrix display. 5 | # This example and library is meant to work with Adafruit CircuitPython API. 6 | # Author: Tony DiCola 7 | # License: Public Domain 8 | 9 | # Import all board pins. 10 | import time 11 | 12 | import board 13 | import busio 14 | 15 | # Import the HT16K33 LED matrix module. 16 | from adafruit_ht16k33 import matrix 17 | 18 | # Create the I2C interface. 19 | i2c = busio.I2C(board.SCL, board.SDA) 20 | 21 | # Create the matrix class. 22 | # This creates a 16x8 matrix: 23 | matrix = matrix.Matrix16x8(i2c) 24 | # Or this creates a 16x8 matrix backpack: 25 | # matrix = matrix.MatrixBackpack16x8(i2c) 26 | # Or this creates a 8x8 matrix: 27 | # matrix = matrix.Matrix8x8(i2c) 28 | # Or this creates a 8x8 bicolor matrix: 29 | # matrix = matrix.Matrix8x8x2(i2c) 30 | # Finally you can optionally specify a custom I2C address of the HT16k33 like: 31 | # matrix = matrix.Matrix16x8(i2c, address=0x70) 32 | 33 | # Clear the matrix. 34 | matrix.fill(0) 35 | 36 | # Set a pixel in the origin 0, 0 position. 37 | matrix[0, 0] = 1 38 | # Set a pixel in the middle 8, 4 position. 39 | matrix[8, 4] = 1 40 | # Set a pixel in the opposite 15, 7 position. 41 | matrix[15, 7] = 1 42 | 43 | time.sleep(2) 44 | 45 | # Draw a Smiley Face 46 | matrix.fill(0) 47 | 48 | for row in range(2, 6): 49 | matrix[row, 0] = 1 50 | matrix[row, 7] = 1 51 | 52 | for column in range(2, 6): 53 | matrix[0, column] = 1 54 | matrix[7, column] = 1 55 | 56 | matrix[1, 1] = 1 57 | matrix[1, 6] = 1 58 | matrix[6, 1] = 1 59 | matrix[6, 6] = 1 60 | matrix[2, 5] = 1 61 | matrix[5, 5] = 1 62 | matrix[2, 3] = 1 63 | matrix[5, 3] = 1 64 | matrix[3, 2] = 1 65 | matrix[4, 2] = 1 66 | 67 | # Move the Smiley Face Around 68 | while True: 69 | for frame in range(0, 8): 70 | matrix.shift_right(True) 71 | time.sleep(0.05) 72 | for frame in range(0, 8): 73 | matrix.shift_down(True) 74 | time.sleep(0.05) 75 | for frame in range(0, 8): 76 | matrix.shift_left(True) 77 | time.sleep(0.05) 78 | for frame in range(0, 8): 79 | matrix.shift_up(True) 80 | time.sleep(0.05) 81 | -------------------------------------------------------------------------------- /examples/ht16k33_matrix_text_example.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Basic example of using FrameBuffer to create and scroll text on the matrix. 5 | 6 | # Requires: adafruit_framebuf 7 | 8 | import adafruit_framebuf 9 | import board 10 | import busio 11 | 12 | # Import the HT16K33 LED matrix module. 13 | from adafruit_ht16k33 import matrix 14 | 15 | # Create the I2C interface. 16 | i2c = busio.I2C(board.SCL, board.SDA) 17 | 18 | # Create the matrix class. 19 | # This creates a 16x8 matrix: 20 | matrix = matrix.Matrix16x8(i2c) 21 | 22 | # Low brightness so it's easier to look at 23 | matrix.brightness = 0 24 | 25 | # Clear the matrix. 26 | matrix.fill(0) 27 | 28 | text_to_show = "Hello Blinka" 29 | 30 | # Create a framebuffer for our display 31 | buf = bytearray(16) # 1 bytes tall x 16 wide = 16 bytes 32 | fb = adafruit_framebuf.FrameBuffer(buf, 16, 8, adafruit_framebuf.MVLSB) 33 | 34 | 35 | while True: 36 | for i in range(len(text_to_show) * 8): 37 | fb.fill(0) 38 | fb.text(text_to_show, -i + 16, 0, color=1) 39 | # turn all LEDs off 40 | matrix.fill(0) 41 | for x in range(16): 42 | # using the FrameBuffer text result 43 | bite = buf[x] 44 | for y in range(8): 45 | bit = 1 << y & bite 46 | # if bit > 0 then set the pixel brightness 47 | if bit: 48 | matrix[16 - x, y + 1] = 1 49 | -------------------------------------------------------------------------------- /examples/ht16k33_segments_14x4_demo.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | 8 | from adafruit_ht16k33 import segments 9 | 10 | # Create the display object. 11 | # Display connected to STEMMA QT connector. 12 | display = segments.Seg14x4(board.STEMMA_I2C()) 13 | # Display connected to I2C pins. 14 | # display = segments.Seg14x4(board.I2C()) # uses board.SCL and board.SDA 15 | 16 | # This section displays four 0's across the display. The code shows four 17 | # different ways to use the set_digit_raw function. Each is labeled below. 18 | # 16-bit Hexadecimal number 19 | display.set_digit_raw(0, 0x2D3F) 20 | time.sleep(0.2) 21 | # 16-bit Binary number 22 | display.set_digit_raw(1, 0b0010110100111111) 23 | time.sleep(0.2) 24 | # 8-bit Binary Tuple 25 | display.set_digit_raw(2, (0b00101101, 0b00111111)) 26 | time.sleep(0.2) 27 | # 8-bit Hexadecimal List 28 | display.set_digit_raw(3, [0x2D, 0x3F]) 29 | time.sleep(0.2) 30 | 31 | # Delay between. 32 | time.sleep(2) 33 | 34 | # Scroll "Hello, world!" across the display. Setting the loop parameter to false allows you to 35 | # tell the marquee function to run only once. By default, marquee loops indefinitely. 36 | display.marquee("Hello, world!", loop=False) 37 | 38 | # Delay between. 39 | time.sleep(2) 40 | 41 | # Scroll special characters, uppercase and lowercase letters, and numbers across 42 | # the display in a loop. This section will continue to run indefinitely. 43 | display.marquee("".join(chr(character) for character in range(ord("!"), ord("z") + 1))) 44 | -------------------------------------------------------------------------------- /examples/ht16k33_segments_7x4customchars.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | Basic example of setting custom characters on a LED segment display. 7 | """ 8 | 9 | # Import all board pins. 10 | import time 11 | 12 | import board 13 | import busio 14 | 15 | from adafruit_ht16k33 import segments 16 | 17 | # Create the character dictionary 18 | # You can use the list normally referenced as a starting point 19 | custom_chars = {} 20 | typical_list_values = segments.NUMBERS 21 | typical_list_chars = list("0123456789abcdef-") 22 | for char, value in zip(typical_list_chars, typical_list_values): 23 | custom_chars[char] = value 24 | 25 | # Add the custom characters you want 26 | custom_chars["s"] = 0b01101101 27 | custom_chars["r"] = 0b01010000 28 | custom_chars["o"] = 0b00111111 29 | custom_chars["l"] = 0b00110000 30 | custom_chars["i"] = 0b00010000 31 | custom_chars["n"] = 0b01010100 32 | custom_chars["g"] = 0b01101111 33 | 34 | # Create the I2C interface. 35 | i2c = busio.I2C(board.SCL, board.SDA) 36 | display = segments.Seg7x4(i2c, char_dict=custom_chars) 37 | 38 | # Clear the display. 39 | display.fill(0) 40 | 41 | # Now you can print custom text 42 | display.print("cool") 43 | time.sleep(3) 44 | 45 | # You can also marquee custom text 46 | display.marquee("scrolling... ", 0.2) 47 | -------------------------------------------------------------------------------- /examples/ht16k33_segments_multi_display.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Basic example of setting digits on two LED segment displays. 5 | # This example and library is meant to work with Adafruit CircuitPython API. 6 | # Author: Melissa LeBlanc-Williams 7 | # License: Public Domain 8 | 9 | import time 10 | 11 | # Import all board pins. 12 | import board 13 | import busio 14 | 15 | # Import the HT16K33 LED segment module. 16 | from adafruit_ht16k33 import segments 17 | 18 | # Create the I2C interface. 19 | i2c = busio.I2C(board.SCL, board.SDA) 20 | 21 | # Create the LED segment class. 22 | # This creates a 7 segment 4 character display: 23 | display = segments.Seg7x4(i2c, address=(0x70, 0x71)) 24 | # Or this creates a 14 segment alphanumeric 4 character display: 25 | # display = segments.Seg14x4(i2c, address=(0x70, 0x71)) 26 | 27 | # Clear the display. 28 | display.fill(0) 29 | 30 | # Can just print a number 31 | display.print(12345678) 32 | 33 | time.sleep(2) 34 | 35 | # Or, can print a hexadecimal value 36 | display.fill(0) 37 | display.print_hex(0xFF23) 38 | time.sleep(2) 39 | 40 | # Or, print the time 41 | display.fill(0) 42 | display.print("12:30") 43 | time.sleep(2) 44 | 45 | display.colon = False 46 | 47 | display.fill(0) 48 | # Or, can set indivdual digits / characters 49 | # Set the first character to '1': 50 | display[0] = "1" 51 | # Set the second character to '2': 52 | display[1] = "2" 53 | # Set the third character to 'A': 54 | display[2] = "A" 55 | # Set the forth character to 'B': 56 | display[3] = "B" 57 | display[4] = "C" 58 | display[5] = "D" 59 | display[6] = "E" 60 | display[7] = "F" 61 | time.sleep(2) 62 | 63 | # Or, can even set the segments to make up characters 64 | if isinstance(display, segments.Seg7x4): 65 | # 7-segment raw digits 66 | display.set_digit_raw(0, 0xFF) 67 | display.set_digit_raw(1, 0b11111111) 68 | display.set_digit_raw(2, 0x79) 69 | display.set_digit_raw(3, 0b01111001) 70 | else: 71 | # 14-segment raw digits. Same character (0) displayed using four different methods. 72 | # 16-bit Hexadecimal number 73 | display.set_digit_raw(0, 0x2D3F) 74 | # 16-bit Binary number 75 | display.set_digit_raw(1, 0b0010110100111111) 76 | # 8-bit Binary Tuple 77 | display.set_digit_raw(2, (0b00101101, 0b00111111)) 78 | # 8-bit Hexadecimal List 79 | display.set_digit_raw(3, [0x2D, 0x3F]) 80 | time.sleep(2) 81 | 82 | # Show a looping marquee 83 | display.marquee("Deadbeef 192.168.100.102... ", 0.2) 84 | -------------------------------------------------------------------------------- /examples/ht16k33_segments_non_blocking_marquee.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2023 Tim Cocks for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | """ 4 | Example that uses Non-Blocking Marquee to scroll text on 14x4 segment 5 | while also blinking the on-board neopixel at a different rate from the 6 | marquee scrolling. 7 | """ 8 | 9 | import time 10 | 11 | import board 12 | import neopixel 13 | 14 | import adafruit_ht16k33.segments 15 | 16 | i2c = board.I2C() 17 | segment_display = adafruit_ht16k33.segments.Seg14x4(i2c) 18 | 19 | pixel_pin = board.NEOPIXEL 20 | pixels = neopixel.NeoPixel(pixel_pin, 1, brightness=0.1, auto_write=True) 21 | 22 | pixels[0] = 0xFF0000 23 | last_blink = 0 24 | while True: 25 | now = time.monotonic() 26 | if now > last_blink + 0.3: 27 | if pixels[0] == (255, 0, 255): 28 | pixels[0] = 0x00FF00 29 | else: 30 | pixels[0] = 0xFF00FF 31 | last_blink = now 32 | segment_display.non_blocking_marquee("CircuitPython <3", delay=0.2) 33 | -------------------------------------------------------------------------------- /examples/ht16k33_segments_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Basic example of setting digits on a LED segment display. 5 | # This example and library is meant to work with Adafruit CircuitPython API. 6 | # Author: Tony DiCola 7 | # License: Public Domain 8 | 9 | import time 10 | 11 | # Import all board pins. 12 | import board 13 | import busio 14 | 15 | # Import the HT16K33 LED segment module. 16 | from adafruit_ht16k33 import segments 17 | 18 | # Create the I2C interface. 19 | i2c = busio.I2C(board.SCL, board.SDA) 20 | 21 | # Create the LED segment class. 22 | # This creates a 7 segment 4 character display: 23 | display = segments.Seg7x4(i2c) 24 | # Or this creates a 14 segment alphanumeric 4 character display: 25 | # display = segments.Seg14x4(i2c) 26 | # Or this creates a big 7 segment 4 character display 27 | # display = segments.BigSeg7x4(i2c) 28 | # Finally you can optionally specify a custom I2C address of the HT16k33 like: 29 | # display = segments.Seg7x4(i2c, address=0x70) 30 | 31 | # Clear the display. 32 | display.fill(0) 33 | 34 | # Can just print a number 35 | display.print(42) 36 | time.sleep(2) 37 | 38 | # Or, can print a hexadecimal value 39 | display.print_hex(0xFF23) 40 | time.sleep(2) 41 | 42 | # Or, print the time 43 | display.print("12:30") 44 | time.sleep(2) 45 | 46 | display.colon = False 47 | 48 | # Or, can set indivdual digits / characters 49 | # Set the first character to '1': 50 | display[0] = "1" 51 | # Set the second character to '2': 52 | display[1] = "2" 53 | # Set the third character to 'A': 54 | display[2] = "A" 55 | # Set the forth character to 'B': 56 | display[3] = "B" 57 | time.sleep(2) 58 | 59 | # Or, can even set the segments to make up characters 60 | if isinstance(display, segments.Seg7x4): 61 | # 7-segment raw digits 62 | display.set_digit_raw(0, 0xFF) 63 | display.set_digit_raw(1, 0b11111111) 64 | display.set_digit_raw(2, 0x79) 65 | display.set_digit_raw(3, 0b01111001) 66 | else: 67 | # 14-segment raw digits. Same character (0) displayed using four different methods. 68 | # 16-bit Hexadecimal number 69 | display.set_digit_raw(0, 0x2D3F) 70 | # 16-bit Binary number 71 | display.set_digit_raw(1, 0b0010110100111111) 72 | # 8-bit Binary Tuple 73 | display.set_digit_raw(2, (0b00101101, 0b00111111)) 74 | # 8-bit Hexadecimal List 75 | display.set_digit_raw(3, [0x2D, 0x3F]) 76 | time.sleep(2) 77 | 78 | # Show a looping marquee 79 | display.marquee("Deadbeef 192.168.100.102... ", 0.2) 80 | -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | pillow 6 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools", 8 | "wheel", 9 | "setuptools-scm", 10 | ] 11 | 12 | [project] 13 | name = "adafruit-circuitpython-ht16k33" 14 | description = "CircuitPython library for HT16K33 LED matrices and segment displays." 15 | version = "0.0.0+auto.0" 16 | readme = "README.rst" 17 | authors = [ 18 | {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} 19 | ] 20 | urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33"} 21 | keywords = [ 22 | "adafruit", 23 | "ht16k33", 24 | "led", 25 | "matrix", 26 | "segment", 27 | "displays", 28 | "hardware", 29 | "micropython", 30 | "circuitpython", 31 | ] 32 | license = {text = "MIT"} 33 | classifiers = [ 34 | "Intended Audience :: Developers", 35 | "Topic :: Software Development :: Libraries", 36 | "Topic :: Software Development :: Embedded Systems", 37 | "Topic :: System :: Hardware", 38 | "License :: OSI Approved :: MIT License", 39 | "Programming Language :: Python :: 3", 40 | ] 41 | dynamic = ["dependencies", "optional-dependencies"] 42 | 43 | [tool.setuptools] 44 | packages = ["adafruit_ht16k33"] 45 | 46 | [tool.setuptools.dynamic] 47 | dependencies = {file = ["requirements.txt"]} 48 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 49 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka 6 | adafruit-circuitpython-typing~=1.6 7 | adafruit-circuitpython-busdevice 8 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | target-version = "py38" 6 | line-length = 100 7 | 8 | [lint] 9 | preview = true 10 | select = ["I", "PL", "UP"] 11 | 12 | extend-select = [ 13 | "D419", # empty-docstring 14 | "E501", # line-too-long 15 | "W291", # trailing-whitespace 16 | "PLC0414", # useless-import-alias 17 | "PLC2401", # non-ascii-name 18 | "PLC2801", # unnecessary-dunder-call 19 | "PLC3002", # unnecessary-direct-lambda-call 20 | "E999", # syntax-error 21 | "PLE0101", # return-in-init 22 | "F706", # return-outside-function 23 | "F704", # yield-outside-function 24 | "PLE0116", # continue-in-finally 25 | "PLE0117", # nonlocal-without-binding 26 | "PLE0241", # duplicate-bases 27 | "PLE0302", # unexpected-special-method-signature 28 | "PLE0604", # invalid-all-object 29 | "PLE0605", # invalid-all-format 30 | "PLE0643", # potential-index-error 31 | "PLE0704", # misplaced-bare-raise 32 | "PLE1141", # dict-iter-missing-items 33 | "PLE1142", # await-outside-async 34 | "PLE1205", # logging-too-many-args 35 | "PLE1206", # logging-too-few-args 36 | "PLE1307", # bad-string-format-type 37 | "PLE1310", # bad-str-strip-call 38 | "PLE1507", # invalid-envvar-value 39 | "PLE2502", # bidirectional-unicode 40 | "PLE2510", # invalid-character-backspace 41 | "PLE2512", # invalid-character-sub 42 | "PLE2513", # invalid-character-esc 43 | "PLE2514", # invalid-character-nul 44 | "PLE2515", # invalid-character-zero-width-space 45 | "PLR0124", # comparison-with-itself 46 | "PLR0202", # no-classmethod-decorator 47 | "PLR0203", # no-staticmethod-decorator 48 | "UP004", # useless-object-inheritance 49 | "PLR0206", # property-with-parameters 50 | "PLR0904", # too-many-public-methods 51 | "PLR0911", # too-many-return-statements 52 | "PLR0912", # too-many-branches 53 | "PLR0913", # too-many-arguments 54 | "PLR0914", # too-many-locals 55 | "PLR0915", # too-many-statements 56 | "PLR0916", # too-many-boolean-expressions 57 | "PLR1702", # too-many-nested-blocks 58 | "PLR1704", # redefined-argument-from-local 59 | "PLR1711", # useless-return 60 | "C416", # unnecessary-comprehension 61 | "PLR1733", # unnecessary-dict-index-lookup 62 | "PLR1736", # unnecessary-list-index-lookup 63 | 64 | # ruff reports this rule is unstable 65 | #"PLR6301", # no-self-use 66 | 67 | "PLW0108", # unnecessary-lambda 68 | "PLW0120", # useless-else-on-loop 69 | "PLW0127", # self-assigning-variable 70 | "PLW0129", # assert-on-string-literal 71 | "B033", # duplicate-value 72 | "PLW0131", # named-expr-without-context 73 | "PLW0245", # super-without-brackets 74 | "PLW0406", # import-self 75 | "PLW0602", # global-variable-not-assigned 76 | "PLW0603", # global-statement 77 | "PLW0604", # global-at-module-level 78 | 79 | # fails on the try: import typing used by libraries 80 | #"F401", # unused-import 81 | 82 | "F841", # unused-variable 83 | "E722", # bare-except 84 | "PLW0711", # binary-op-exception 85 | "PLW1501", # bad-open-mode 86 | "PLW1508", # invalid-envvar-default 87 | "PLW1509", # subprocess-popen-preexec-fn 88 | "PLW2101", # useless-with-lock 89 | "PLW3301", # nested-min-max 90 | ] 91 | 92 | ignore = [ 93 | "PLR2004", # magic-value-comparison 94 | "UP030", # format literals 95 | "PLW1514", # unspecified-encoding 96 | "PLR0913", # too-many-arguments 97 | "PLR0915", # too-many-statements 98 | "PLR0917", # too-many-positional-arguments 99 | "PLR0904", # too-many-public-methods 100 | "PLR0912", # too-many-branches 101 | "PLR0916", # too-many-boolean-expressions 102 | "PLR1702", # too-many-nested-blocks 103 | "PLR0911", # too-many-returns 104 | ] 105 | 106 | [format] 107 | line-ending = "lf" 108 | --------------------------------------------------------------------------------