├── .codespellrc ├── .github ├── dependabot.yml └── workflows │ ├── check-arduino.yml │ ├── compile-examples.yml │ ├── report-size-deltas.yml │ ├── spell-check.yml │ └── sync-labels.yml ├── LICENSE.txt ├── README.adoc ├── docs ├── api.md └── readme.md ├── examples ├── Arduino │ ├── TFTBitmapLogo │ │ ├── TFTBitmapLogo.ino │ │ └── arduino.bmp │ ├── TFTColorPicker │ │ └── TFTColorPicker.ino │ ├── TFTDisplayText │ │ └── TFTDisplayText.ino │ ├── TFTEtchASketch │ │ └── TFTEtchASketch.ino │ ├── TFTGraph │ │ └── TFTGraph.ino │ └── TFTPong │ │ └── TFTPong.ino └── Esplora │ ├── EsploraTFTBitmapLogo │ ├── EsploraTFTBitmapLogo.ino │ └── arduino.bmp │ ├── EsploraTFTColorPicker │ └── EsploraTFTColorPicker.ino │ ├── EsploraTFTEtchASketch │ └── EsploraTFTEtchASketch.ino │ ├── EsploraTFTGraph │ └── EsploraTFTGraph.ino │ ├── EsploraTFTHorizon │ └── EsploraTFTHorizon.ino │ ├── EsploraTFTPong │ └── EsploraTFTPong.ino │ └── EsploraTFTTemp │ └── EsploraTFTTemp.ino ├── extras ├── Adafruit-README.txt ├── Adafruit-license.txt └── README.md ├── keywords.txt ├── library.properties └── src ├── TFT.cpp ├── TFT.h └── utility ├── Adafruit_GFX.cpp ├── Adafruit_GFX.h ├── Adafruit_ST7735.cpp ├── Adafruit_ST7735.h ├── PImage.h ├── glcdfont.c └── keywords.txt /.codespellrc: -------------------------------------------------------------------------------- 1 | # See: https://github.com/codespell-project/codespell#using-a-config-file 2 | [codespell] 3 | # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: 4 | ignore-words-list = , 5 | check-filenames = 6 | check-hidden = 7 | skip = ./.git,./extras,./src/utility 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file 2 | version: 2 3 | 4 | updates: 5 | # Configure check for outdated GitHub Actions actions in workflows. 6 | # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot 7 | - package-ecosystem: github-actions 8 | directory: / # Check the repository's workflows under /.github/workflows/ 9 | schedule: 10 | interval: daily 11 | -------------------------------------------------------------------------------- /.github/workflows/check-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Check Arduino 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | lint: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Arduino Lint 22 | uses: arduino/arduino-lint-action@v2 23 | with: 24 | compliance: specification 25 | library-manager: update 26 | # Always use this setting for official repositories. Remove for 3rd party projects. 27 | official: true 28 | project-type: library 29 | -------------------------------------------------------------------------------- /.github/workflows/compile-examples.yml: -------------------------------------------------------------------------------- 1 | name: Compile Examples 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | paths: 7 | - ".github/workflows/compile-examples.yml" 8 | - "examples/**" 9 | - "src/**" 10 | pull_request: 11 | paths: 12 | - ".github/workflows/compile-examples.yml" 13 | - "examples/**" 14 | - "src/**" 15 | schedule: 16 | # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). 17 | - cron: "0 8 * * TUE" 18 | workflow_dispatch: 19 | repository_dispatch: 20 | 21 | jobs: 22 | build: 23 | name: ${{ matrix.board.fqbn }} 24 | runs-on: ubuntu-latest 25 | 26 | env: 27 | SKETCHES_REPORTS_PATH: sketches-reports 28 | 29 | strategy: 30 | fail-fast: false 31 | 32 | matrix: 33 | board: 34 | - fqbn: arduino:avr:nano 35 | platforms: | 36 | - name: arduino:avr 37 | type: arduino 38 | artifact-name-suffix: arduino-avr-uno 39 | - fqbn: arduino:avr:mega 40 | platforms: | 41 | - name: arduino:avr 42 | type: arduino 43 | artifact-name-suffix: arduino-avr-mega 44 | - fqbn: arduino:avr:leonardo 45 | platforms: | 46 | - name: arduino:avr 47 | type: arduino 48 | artifact-name-suffix: arduino-avr-leonardo 49 | - fqbn: arduino:avr:esplora 50 | platforms: | 51 | - name: arduino:avr 52 | type: esplora 53 | artifact-name-suffix: arduino-avr-esplora 54 | - fqbn: arduino:megaavr:nona4809 55 | platforms: | 56 | - name: arduino:megaavr 57 | type: arduino 58 | artifact-name-suffix: arduino-megaavr-nona4809 59 | - fqbn: arduino:sam:arduino_due_x_dbg 60 | platforms: | 61 | - name: arduino:sam 62 | type: arduino 63 | artifact-name-suffix: arduino-sam-arduino_due_x_dbg 64 | - fqbn: arduino:samd:mkrzero 65 | platforms: | 66 | - name: arduino:samd 67 | type: arduino 68 | artifact-name-suffix: arduino-samd-mkrzero 69 | 70 | # Make board type-specific customizations to the matrix jobs 71 | include: 72 | - board: 73 | # Boards to compile the Esplora-specific examples for 74 | type: esplora 75 | libraries: | 76 | - name: Esplora 77 | sketch-paths: | 78 | - examples/Esplora 79 | - board: 80 | # Boards to compile the general examples for 81 | type: arduino 82 | libraries: "" 83 | sketch-paths: | 84 | - examples/Arduino 85 | 86 | steps: 87 | - name: Checkout repository 88 | uses: actions/checkout@v4 89 | 90 | - name: Compile examples 91 | uses: arduino/compile-sketches@v1 92 | with: 93 | github-token: ${{ secrets.GITHUB_TOKEN }} 94 | fqbn: ${{ matrix.board.fqbn }} 95 | platforms: ${{ matrix.board.platforms }} 96 | libraries: | 97 | # Install the library from the local path. 98 | - source-path: ./ 99 | - name: SD 100 | ${{ matrix.libraries }} 101 | sketch-paths: | 102 | ${{ matrix.sketch-paths }} 103 | enable-deltas-report: true 104 | sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} 105 | 106 | - name: Save sketches report as workflow artifact 107 | uses: actions/upload-artifact@v4 108 | with: 109 | if-no-files-found: error 110 | path: ${{ env.SKETCHES_REPORTS_PATH }} 111 | name: sketches-report-${{ matrix.board.artifact-name-suffix }} 112 | -------------------------------------------------------------------------------- /.github/workflows/report-size-deltas.yml: -------------------------------------------------------------------------------- 1 | name: Report Size Deltas 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | paths: 7 | - ".github/workflows/report-size-deltas.yml" 8 | schedule: 9 | # Run at the minimum interval allowed by GitHub Actions. 10 | # Note: GitHub Actions periodically has outages which result in workflow failures. 11 | # In this event, the workflows will start passing again once the service recovers. 12 | - cron: "*/5 * * * *" 13 | workflow_dispatch: 14 | repository_dispatch: 15 | 16 | jobs: 17 | report: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Comment size deltas reports to PRs 21 | uses: arduino/report-size-deltas@v1 22 | with: 23 | # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow 24 | sketches-reports-source: ^sketches-report-.+ 25 | -------------------------------------------------------------------------------- /.github/workflows/spell-check.yml: -------------------------------------------------------------------------------- 1 | name: Spell Check 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | spellcheck: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Spell check 22 | uses: codespell-project/actions-codespell@master 23 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md 2 | name: Sync Labels 3 | 4 | # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows 5 | on: 6 | push: 7 | paths: 8 | - ".github/workflows/sync-labels.ya?ml" 9 | - ".github/label-configuration-files/*.ya?ml" 10 | pull_request: 11 | paths: 12 | - ".github/workflows/sync-labels.ya?ml" 13 | - ".github/label-configuration-files/*.ya?ml" 14 | schedule: 15 | # Run daily at 8 AM UTC to sync with changes to shared label configurations. 16 | - cron: "0 8 * * *" 17 | workflow_dispatch: 18 | repository_dispatch: 19 | 20 | env: 21 | CONFIGURATIONS_FOLDER: .github/label-configuration-files 22 | CONFIGURATIONS_ARTIFACT: label-configuration-files 23 | 24 | jobs: 25 | check: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@v4 31 | 32 | - name: Download JSON schema for labels configuration file 33 | id: download-schema 34 | uses: carlosperate/download-file-action@v2 35 | with: 36 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json 37 | location: ${{ runner.temp }}/label-configuration-schema 38 | 39 | - name: Install JSON schema validator 40 | run: | 41 | sudo npm install \ 42 | --global \ 43 | ajv-cli \ 44 | ajv-formats 45 | 46 | - name: Validate local labels configuration 47 | run: | 48 | # See: https://github.com/ajv-validator/ajv-cli#readme 49 | ajv validate \ 50 | --all-errors \ 51 | -c ajv-formats \ 52 | -s "${{ steps.download-schema.outputs.file-path }}" \ 53 | -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" 54 | 55 | download: 56 | needs: check 57 | runs-on: ubuntu-latest 58 | 59 | strategy: 60 | matrix: 61 | filename: 62 | # Filenames of the shared configurations to apply to the repository in addition to the local configuration. 63 | # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels 64 | - universal.yml 65 | 66 | steps: 67 | - name: Download 68 | uses: carlosperate/download-file-action@v2 69 | with: 70 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} 71 | 72 | - name: Pass configuration files to next job via workflow artifact 73 | uses: actions/upload-artifact@v4 74 | with: 75 | path: | 76 | *.yaml 77 | *.yml 78 | if-no-files-found: error 79 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 80 | 81 | sync: 82 | needs: download 83 | runs-on: ubuntu-latest 84 | 85 | steps: 86 | - name: Set environment variables 87 | run: | 88 | # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable 89 | echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" 90 | 91 | - name: Determine whether to dry run 92 | id: dry-run 93 | if: > 94 | github.event_name == 'pull_request' || 95 | ( 96 | ( 97 | github.event_name == 'push' || 98 | github.event_name == 'workflow_dispatch' 99 | ) && 100 | github.ref != format('refs/heads/{0}', github.event.repository.default_branch) 101 | ) 102 | run: | 103 | # Use of this flag in the github-label-sync command will cause it to only check the validity of the 104 | # configuration. 105 | echo "::set-output name=flag::--dry-run" 106 | 107 | - name: Checkout repository 108 | uses: actions/checkout@v4 109 | 110 | - name: Download configuration files artifact 111 | uses: actions/download-artifact@v4 112 | with: 113 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 114 | path: ${{ env.CONFIGURATIONS_FOLDER }} 115 | 116 | - name: Remove unneeded artifact 117 | uses: geekyeggo/delete-artifact@v5 118 | with: 119 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 120 | 121 | - name: Merge label configuration files 122 | run: | 123 | # Merge all configuration files 124 | shopt -s extglob 125 | cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" 126 | 127 | - name: Install github-label-sync 128 | run: sudo npm install --global github-label-sync 129 | 130 | - name: Sync labels 131 | env: 132 | GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 133 | run: | 134 | # See: https://github.com/Financial-Times/github-label-sync 135 | github-label-sync \ 136 | --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ 137 | ${{ steps.dry-run.outputs.flag }} \ 138 | ${{ github.repository }} 139 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | :repository-owner: arduino-libraries 2 | :repository-name: TFT 3 | 4 | = {repository-name} Library for Arduino = 5 | 6 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] 7 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] 8 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] 9 | 10 | This library enables an Arduino board to communicate with the Arduino TFT LCD screen. It simplifies the process for drawing shapes, lines, images, and text to the screen. 11 | 12 | For more information about this library please visit us at 13 | http://www.arduino.cc/en/Reference/TFTLibrary 14 | -------------------------------------------------------------------------------- /docs/api.md: -------------------------------------------------------------------------------- 1 | # TFT LCD library 2 | 3 | ## Functions 4 | 5 | ### `TFT` 6 | 7 | #### Description 8 | The base class for drawing to the Arduino TFT screen. Use this to create an named instance of the TFT class to refer to in your sketch. 9 | 10 | if using the Arduino Explora, you do not need to call this, all references to the screen are handled through EsploraTFT. 11 | 12 | #### Syntax 13 | 14 | ``` 15 | TFT(cs, dc, rst); for using hardware SPI 16 | TFT(cs, dc, mosi, sclk, rst); for use on any pins 17 | ``` 18 | 19 | #### Parameters 20 | cs : int, pin for chip select 21 | dc : int, pin used for 22 | rst : int, pin used for reset 23 | mosi : int, pin used for MOSI communication when not using hardware SPI 24 | sclk : int, pin used for the shared clock, when not using hardware SPI 25 | #### Returns 26 | none 27 | 28 | #### Example 29 | 30 | ``` 31 | #include 32 | #include // Arduino LCD library 33 | 34 | #define cs 10 35 | #define dc 9 36 | #define rst 8 37 | 38 | TFT screen = TFT(cs, dc, rst); 39 | 40 | void setup() { 41 | // initialize the screen 42 | screen.begin(); 43 | 44 | // make the background black 45 | screen.background(0,0,0); 46 | 47 | // set the stroke color to white 48 | screen.stroke(255,255,255); 49 | 50 | // turn off fill coloring 51 | screen.noFill(); 52 | 53 | // draw a rectangle in the center of screen 54 | screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10); 55 | } 56 | 57 | void loop() { 58 | 59 | } 60 | 61 | ``` 62 | 63 | ### `EsploraTFT` 64 | 65 | #### Description 66 | This is the named instance of the TFT class when targeting the Arduino Esplora board. 67 | 68 | #### Syntax 69 | 70 | ``` 71 | EsploraTFT 72 | 73 | ``` 74 | 75 | #### Parameters 76 | none 77 | 78 | #### Returns 79 | none 80 | 81 | #### Example 82 | 83 | ``` 84 | #include 85 | #include 86 | #include // Arduino LCD library 87 | 88 | void setup() { 89 | // initialize the screen 90 | EsploraTFT.begin(); 91 | 92 | // make the background white 93 | EsploraTFT.background(255,255,255); 94 | } 95 | 96 | void loop() { 97 | 98 | } 99 | 100 | ``` 101 | 102 | ### `begin()` 103 | 104 | #### Description 105 | 106 | Must be called to initialize the Arduino GLCD screen before drawing anything. 107 | 108 | #### Syntax 109 | 110 | ``` 111 | screen.begin() 112 | 113 | ``` 114 | 115 | #### Parameters 116 | none 117 | 118 | #### Returns 119 | none 120 | 121 | #### Example 122 | 123 | ``` 124 | #include 125 | #include // Arduino LCD library 126 | 127 | #define cs 10 128 | #define dc 9 129 | #define rst 8 130 | 131 | TFT screen = TFT(cs, dc, rst); 132 | 133 | void setup() { 134 | // initialize the screen 135 | screen.begin(); 136 | 137 | // make the background white 138 | screen.background(255,255,255); 139 | } 140 | 141 | void loop() { 142 | 143 | } 144 | 145 | ``` 146 | 147 | ### `background()` 148 | 149 | #### Description 150 | 151 | Erases everything currently on the LCD screen with the indicated color. Can be used in loop() to clear the screen. 152 | 153 | While background() expects 8-bit values for each of the red, green, and blue channels, the screen does not display with this fidelity. The red and blue values are scaled to 5-bit color (32 discrete steps), and the green is 6-bit color (64 discrete steps). 154 | 155 | #### Syntax 156 | 157 | ``` 158 | screen.background(red, green, blue); 159 | 160 | ``` 161 | 162 | #### Parameters 163 | red : int 0-255 164 | green : int 0-255 165 | blue : int 0-255 166 | #### Returns 167 | none 168 | 169 | #### Example 170 | 171 | ``` 172 | #include 173 | #include // Arduino LCD library 174 | 175 | #define cs 10 176 | #define dc 9 177 | #define rst 8 178 | 179 | TFT screen = TFT(cs, dc, rst); 180 | 181 | void setup() { 182 | // initialize the screen 183 | screen.begin(); 184 | 185 | // make the background white 186 | screen.background(255,255,255); 187 | } 188 | 189 | void loop() { 190 | 191 | } 192 | 193 | ``` 194 | 195 | ### `stroke()` 196 | 197 | #### Description 198 | 199 | Called before drawing an object on screen, it sets the color of lines and borders around shapes. 200 | 201 | stroke() expects 8-bit values for each of the red, green, and blue channels, but the screen does not display with this fidelity. The red and blue values are scaled to 5-bit color (32 discrete steps), and the green is 6-bit color (64 discrete steps). 202 | 203 | #### Syntax 204 | 205 | ``` 206 | screen.stroke(red, green, blue); 207 | 208 | ``` 209 | 210 | #### Parameters 211 | red : int 0-255 212 | green : int 0-255 213 | blue : int 0-255 214 | #### Returns 215 | none 216 | 217 | #### Example 218 | 219 | ``` 220 | #include 221 | #include // Arduino LCD library 222 | 223 | #define cs 10 224 | #define dc 9 225 | #define rst 8 226 | 227 | TFT screen = TFT(cs, dc, rst); 228 | 229 | void setup() { 230 | // initialize the screen 231 | screen.begin(); 232 | 233 | // make the background black 234 | screen.background(0,0,0); 235 | 236 | // set the stroke color to white 237 | screen.stroke(255,255,255); 238 | 239 | // draw a box with a white outline in the middle of the screen 240 | screen.rect(screen.width()/2+10,screen.height()/2+10,screen.width()/2-10,screen.height()/2-10); 241 | } 242 | 243 | void loop() { 244 | 245 | } 246 | 247 | ``` 248 | 249 | ### `noStroke()` 250 | 251 | #### Description 252 | 253 | After calling this, any shapes drawn on screen will not have an outline stroke color. 254 | 255 | #### Syntax 256 | 257 | ``` 258 | screen.noStroke(); 259 | 260 | ``` 261 | 262 | #### Parameters 263 | none 264 | 265 | #### Returns 266 | none 267 | 268 | #### Example 269 | 270 | ``` 271 | #include 272 | #include // Arduino TFT library 273 | 274 | #define cs 10 275 | #define dc 9 276 | #define rst 8 277 | 278 | TFT screen = TFT(cs, dc, rst); 279 | 280 | void setup() { 281 | // initialize the screen 282 | screen.begin(); 283 | 284 | // make the background black 285 | screen.background(0,0,0); 286 | 287 | // turn the stroke off 288 | screen.noStroke(); 289 | 290 | // set the fill color to white 291 | screen.fill(255,255,255); 292 | 293 | // draw a rectangle in the center of screen 294 | screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10); 295 | } 296 | 297 | void loop() { 298 | 299 | } 300 | 301 | ``` 302 | 303 | ### `fill()` 304 | 305 | #### Description 306 | 307 | Called before drawing an object on screen, it sets the fill color of shapes and text. 308 | 309 | fill() expects 8-bit values for each of the red, green, and blue channels, but the screen does not display with this fidelity. The red and blue values are scaled to 5-bit color (32 discrete steps), and the green is 6-bit color (64 discrete steps). 310 | 311 | #### Syntax 312 | 313 | ``` 314 | screen.fill(red, green, blue); 315 | 316 | ``` 317 | 318 | #### Parameters 319 | red : int 0-255 320 | green : int 0-255 321 | blue : int 0-255 322 | #### Returns 323 | none 324 | 325 | #### Example 326 | 327 | ``` 328 | #include 329 | #include // Arduino TFT library 330 | 331 | #define cs 10 332 | #define dc 9 333 | #define rst 8 334 | 335 | TFT screen = TFT(cs, dc, rst); 336 | 337 | 338 | void setup() { 339 | // initialize the screen 340 | screen.begin(); 341 | 342 | // make the background black 343 | screen.background(0,0,0); 344 | 345 | // set the stroke color to white 346 | screen.fill(255,255,255); 347 | 348 | // draw a white box in the screen center 349 | screen.rect(screen.width()/2+10,screen.height()/2+10,screen.width()/2-10,screen.height()/2-10); 350 | } 351 | 352 | void loop() { 353 | 354 | } 355 | 356 | ``` 357 | 358 | ### `noFill()` 359 | 360 | #### Description 361 | 362 | After calling this, any shapes drawn on screen will not be filled in. 363 | 364 | #### Syntax 365 | 366 | ``` 367 | screen.noFill(); 368 | 369 | ``` 370 | 371 | #### Parameters 372 | none 373 | 374 | #### Returns 375 | none 376 | 377 | #### Example 378 | 379 | ``` 380 | #include 381 | #include // Arduino TFT library 382 | 383 | #define cs 10 384 | #define dc 9 385 | #define rst 8 386 | 387 | TFT screen = TFT(cs, dc, rst); 388 | 389 | void setup() { 390 | // initialize the screen 391 | screen.begin(); 392 | 393 | // make the background black 394 | screen.background(0,0,0); 395 | 396 | // turn the fill off 397 | screen.noFill(); 398 | 399 | // set the stroke color to white 400 | screen.stroke(255,255,255); 401 | 402 | // draw a rectangle in the center of screen 403 | screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10); 404 | } 405 | 406 | void loop() { 407 | 408 | } 409 | 410 | ``` 411 | 412 | ### `text()` 413 | 414 | #### Description 415 | 416 | Write text to the screen at the given coordinates. 417 | 418 | #### Syntax 419 | 420 | ``` 421 | screen.text(text, xPos, yPos); 422 | 423 | ``` 424 | 425 | #### Parameters 426 | text : char array, the text you want to write on the screen 427 | xPos : int, the location on the x-axis you want to start drawing text to the screen 428 | yPos : int, the location on the y-axis you want to start drawing text to the screen 429 | #### Returns 430 | none 431 | 432 | #### Example 433 | 434 | ``` 435 | #include 436 | #include // Arduino TFT library 437 | 438 | #define cs 10 439 | #define dc 9 440 | #define rst 8 441 | 442 | TFT screen = TFT(cs, dc, rst); 443 | 444 | void setup() { 445 | // initialize the screen 446 | screen.begin(); 447 | 448 | // make the background black 449 | screen.background(0,0,0); 450 | 451 | // set the text color to white 452 | screen.stroke(255,255,255); 453 | 454 | // write text to the screen in the top left corner 455 | screen.text("Testing!", 0, 0); 456 | } 457 | 458 | void loop() { 459 | 460 | } 461 | 462 | ``` 463 | 464 | ### `setTextSize()` 465 | 466 | #### Description 467 | 468 | Sets the size of text that follows. The default size is "1". Each change in size increases the text by 10 pixels in height. That is, size 1 = 10 pixels, size 2 =20 pixels, and so on. 469 | 470 | #### Syntax 471 | 472 | ``` 473 | screen.setTextSize(size); 474 | 475 | ``` 476 | 477 | #### Parameters 478 | size : int 1-5 479 | #### Returns 480 | none 481 | 482 | #### Example 483 | 484 | ``` 485 | #include 486 | #include // Arduino TFT library 487 | 488 | #define cs 10 489 | #define dc 9 490 | #define rst 8 491 | 492 | TFT screen = TFT(cs, dc, rst); 493 | 494 | void setup() { 495 | // initialize the screen 496 | screen.begin(); 497 | 498 | // make the background black 499 | screen.background(0,0,0); 500 | 501 | // set the stroke color to white 502 | screen.fill(255,255,255); 503 | 504 | // default text size 505 | screen.setTextSize(1); 506 | // write text to the screen in the top left corner 507 | screen.text("Testing!", 0, 0); 508 | // increase text size 509 | screen.setTextSize(5); 510 | // write text to the screen below 511 | screen.text("BIG!", 0, 10); 512 | } 513 | 514 | void loop() { 515 | 516 | } 517 | 518 | ``` 519 | 520 | ### `begin()` 521 | 522 | #### Description 523 | 524 | Must be called to initialize the Arduino GLCD screen before drawing anything. 525 | 526 | #### Syntax 527 | 528 | ``` 529 | screen.begin() 530 | 531 | ``` 532 | 533 | #### Parameters 534 | none 535 | 536 | #### Returns 537 | none 538 | 539 | #### Example 540 | 541 | ``` 542 | #include 543 | #include // Arduino LCD library 544 | 545 | #define cs 10 546 | #define dc 9 547 | #define rst 8 548 | 549 | TFT screen = TFT(cs, dc, rst); 550 | 551 | void setup() { 552 | // initialize the screen 553 | screen.begin(); 554 | 555 | // make the background white 556 | screen.background(255,255,255); 557 | } 558 | 559 | void loop() { 560 | 561 | } 562 | 563 | ``` 564 | 565 | ### `point()` 566 | 567 | #### Description 568 | 569 | Draws a point at the given coordinates. The first parameter is the horizontal value for the point, the second value is the vertical value for the point. 570 | 571 | #### Syntax 572 | 573 | ``` 574 | screen.point(xPos, yPos); 575 | 576 | ``` 577 | 578 | #### Parameters 579 | xPos : int, the horizontal position of the point 580 | yPos : int, the vertical position of the point 581 | #### Returns 582 | none 583 | 584 | #### Example 585 | 586 | ``` 587 | #include 588 | #include // Arduino TFT library 589 | 590 | #define cs 10 591 | #define dc 9 592 | #define rst 8 593 | 594 | TFT screen = TFT(cs, dc, rst); 595 | 596 | void setup() { 597 | // initialize the screen 598 | screen.begin(); 599 | 600 | // make the background black 601 | screen.background(0,0,0); 602 | 603 | // set the stroke color to white 604 | screen.fill(255,255,255); 605 | 606 | // draw a pixel in the screen's center 607 | screen.point(screen.width()/2, screen.height()/2); 608 | } 609 | 610 | void loop() { 611 | 612 | } 613 | 614 | ``` 615 | 616 | ### `line()` 617 | 618 | #### Description 619 | 620 | Draws a line between two points. Use stroke() to change the color of something drawn with line(). 621 | 622 | #### Syntax 623 | 624 | ``` 625 | screen.line(xStart, yStart, xEnd, yEnd); 626 | 627 | ``` 628 | 629 | #### Parameters 630 | xStart : int, the horizontal position where the line starts 631 | yStart : int, the vertical position where the line starts 632 | xEnd : int, the horizontal position where the line ends 633 | yEnd : int, the vertical position where the line ends 634 | #### Returns 635 | none 636 | 637 | #### Example 638 | 639 | ``` 640 | #include 641 | #include // Arduino TFT library 642 | 643 | #define cs 10 644 | #define dc 9 645 | #define rst 8 646 | 647 | TFT screen = TFT(cs, dc, rst); 648 | 649 | void setup() { 650 | // initialize the screen 651 | screen.begin(); 652 | 653 | // make the background black 654 | screen.background(0,0,0); 655 | 656 | // set the stroke color to white 657 | screen.stroke(255,255,255); 658 | 659 | // draw a diagonal line across the screen's center 660 | screen.line(0, 0, 160, 124); 661 | } 662 | 663 | void loop() { 664 | 665 | } 666 | 667 | ``` 668 | 669 | ### `rect()` 670 | 671 | #### Description 672 | 673 | Draws a rectangle to the TFT screen. rect() takes 4 arguments, the first two are the top left corner of the shape, the last two are the width and height of the shape. 674 | 675 | #### Syntax 676 | 677 | ``` 678 | screen.rect(xStart, yStart, width, height); 679 | 680 | ``` 681 | 682 | #### Parameters 683 | xStart : int, the horizontal position where the line starts 684 | yStart : int, the vertical position where the line starts 685 | width : int, the width of the rectangle 686 | height : int, the height of the rectangle 687 | #### Returns 688 | none 689 | 690 | #### Example 691 | 692 | ``` 693 | #include 694 | #include // Arduino TFT library 695 | 696 | #define cs 10 697 | #define dc 9 698 | #define rst 8 699 | 700 | TFT screen = TFT(cs, dc, rst); 701 | 702 | void setup() { 703 | // initialize the screen 704 | screen.begin(); 705 | 706 | // make the background black 707 | screen.background(0,0,0); 708 | 709 | // set the stroke color to white 710 | screen.stroke(255,255,255); 711 | 712 | // set the fill color to grey 713 | screen.fill(127,127,127); 714 | 715 | // draw a rectangle in the center of screen 716 | screen.rect(screen.width()/2-5, screen.height()/2-5, 10, 10); 717 | } 718 | 719 | void loop() { 720 | 721 | } 722 | 723 | ``` 724 | 725 | ### `width()` 726 | 727 | #### Description 728 | 729 | Reports the width of the TFT screen in pixels. 730 | 731 | #### Syntax 732 | 733 | ``` 734 | screen.width(); 735 | 736 | ``` 737 | 738 | #### Parameters 739 | none 740 | 741 | #### Returns 742 | int : the width of the screen in pixels 743 | 744 | #### Example 745 | 746 | ``` 747 | #include 748 | #include // Arduino TFT library 749 | 750 | #define cs 10 751 | #define dc 9 752 | #define rst 8 753 | 754 | TFT screen = TFT(cs, dc, rst); 755 | 756 | void setup() { 757 | // initialize the screen 758 | screen.begin(); 759 | 760 | // make the background black 761 | screen.background(0,0,0); 762 | 763 | // set the stroke color to white 764 | screen.stroke(255,255,255); 765 | 766 | // set the fill color to grey 767 | screen.fill(127,127,127); 768 | 769 | // draw a rectangle in the center of screen 770 | screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10); 771 | } 772 | 773 | void loop() { 774 | 775 | } 776 | 777 | ``` 778 | 779 | ### `height()` 780 | 781 | #### Description 782 | 783 | Reports the height of the TFT screen in pixels. 784 | 785 | #### Syntax 786 | 787 | ``` 788 | screen.height(); 789 | 790 | ``` 791 | 792 | #### Parameters 793 | none 794 | 795 | #### Returns 796 | int : the height of the screen in pixels 797 | 798 | #### Example 799 | 800 | ``` 801 | #include 802 | #include // Arduino TFT library 803 | 804 | #define cs 10 805 | #define dc 9 806 | #define rst 8 807 | 808 | TFT screen = TFT(cs, dc, rst); 809 | 810 | void setup() { 811 | // initialize the screen 812 | screen.begin(); 813 | 814 | // make the background black 815 | screen.background(0,0,0); 816 | 817 | // set the stroke color to white 818 | screen.stroke(255,255,255); 819 | 820 | // set the fill color to grey 821 | screen.fill(127,127,127); 822 | 823 | // draw a rectangle in the center of screen 824 | screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10); 825 | } 826 | 827 | void loop() { 828 | 829 | } 830 | 831 | ``` 832 | 833 | ### `circle()` 834 | 835 | #### Description 836 | 837 | Draws a circle on the screen. 838 | 839 | The circle is drawn relative to its center point, which means the total diameter will always be an odd number. 840 | 841 | #### Syntax 842 | 843 | ``` 844 | screen.circle(xPos, yPos, radius); 845 | 846 | ``` 847 | 848 | #### Parameters 849 | xPos : int, the location of the center of the circle on the x axis 850 | yPos : int, the location of the center of the circle on the y axis 851 | radius : int, the radius of the circle 852 | #### Returns 853 | int : the width of the screen in pixels 854 | 855 | #### Example 856 | 857 | ``` 858 | #include 859 | #include // Arduino TFT library 860 | 861 | #define cs 10 862 | #define dc 9 863 | #define rst 8 864 | 865 | TFT screen = TFT(cs, dc, rst); 866 | 867 | void setup() { 868 | // initialize the screen 869 | screen.begin(); 870 | 871 | // make the background black 872 | screen.background(0,0,0); 873 | 874 | // set the stroke color to white 875 | screen.stroke(255,255,255); 876 | 877 | // set the fill color to grey 878 | screen.fill(127,127,127); 879 | 880 | // draw a circle in the center of screen 881 | screen.circle(screen.width()/2, screen.height()/2, 10); 882 | } 883 | 884 | void loop() { 885 | 886 | } 887 | 888 | ``` 889 | 890 | ### `image()` 891 | 892 | #### Description 893 | 894 | Draws an image from the SD card to the screen at a specified location. 895 | 896 | #### Syntax 897 | 898 | ``` 899 | screen.image(image, xPos, yPos); 900 | 901 | ``` 902 | 903 | #### Parameters 904 | image : a named instance of PImage. 905 | xPos : int, location on the x-axis to start drawing 906 | yPos : int, location on the y-axis to start drawing 907 | #### Returns 908 | none 909 | 910 | #### Example 911 | 912 | ``` 913 | // this example looks for a file named "logo.bmp" 914 | // on the SD card, and renders it to the screen 915 | #include 916 | #include 917 | #include 918 | #include // Arduino TFT library 919 | 920 | #define SD_CS 8 // Chip select line for SD card in Esplora 921 | 922 | PImage logo; 923 | 924 | void setup() { 925 | // initialize the screen 926 | EsploraTFT.begin(); 927 | // initialize the SD card 928 | SD.begin(SD_CS); 929 | // set the background the black 930 | EsploraTFT.background(0, 0, 0); 931 | 932 | // load the image into the named instance of PImage 933 | logo = EsploraTFT.loadImage("arduino.bmp"); 934 | 935 | // if it is a valid image file, turn the Esplora's LED green 936 | if (logo.isValid()) { 937 | Esplora.writeGreen(255); 938 | } 939 | else{ 940 | // if it is not valid, turn the LED red 941 | Esplora.writeRed(255); 942 | } 943 | 944 | // draw the image on the screen starting at the top left corner 945 | EsploraTFT.image(logo, 0, 0); 946 | 947 | } 948 | 949 | void loop() { 950 | 951 | } 952 | 953 | ``` 954 | 955 | ### `loadImage()` 956 | 957 | #### Description 958 | 959 | Loads an image file from the SD card into a named instance of PImage. The TFT library has the ability to read .bmp files off the root of a SD card and display them on the screen. Images can be smaller or larger than the screen resolution (160x128), but there is no method on the Arduino for image manipulation. The images should be sized before you put them on the SD card. The TFT library has the ability to read .bmp files off the root of a SD card and display them on the screenIt is possible to load 24 bit bmp image only. 960 | 961 | #### Syntax 962 | 963 | ``` 964 | screen.loadImage(name); 965 | 966 | ``` 967 | 968 | #### Parameters 969 | name : char array, the name of the image from the SD card you wish to read 970 | #### Returns 971 | The loaded image 972 | 973 | #### Example 974 | 975 | ``` 976 | // this example looks for a file named "logo.bmp" 977 | // on the SD card, and renders it to the screen 978 | #include 979 | #include 980 | #include 981 | #include // Arduino TFT library 982 | 983 | #define SD_CS 8 // Chip select line for SD card in Esplora 984 | 985 | PImage logo; 986 | 987 | void setup() { 988 | // initialize the screen 989 | EsploraTFT.begin(); 990 | // initialize the SD card 991 | SD.begin(SD_CS); 992 | // set the background the black 993 | EsploraTFT.background(0, 0, 0); 994 | 995 | // load the image into the named instance of PImage 996 | logo = EsploraTFT.loadImage("arduino.bmp"); 997 | 998 | // if it is a valid image file, turn the Esplora's LED green 999 | if (logo.isValid()) { 1000 | Esplora.writeGreen(255); 1001 | } 1002 | else{ 1003 | // if it is not valid, turn the LED red 1004 | Esplora.writeRed(255); 1005 | } 1006 | 1007 | // draw the image on the screen starting at the top left corner 1008 | EsploraTFT.image(logo, 0, 0); 1009 | 1010 | } 1011 | 1012 | void loop() { 1013 | 1014 | } 1015 | 1016 | ``` 1017 | 1018 | ### `PImage` 1019 | 1020 | #### Description 1021 | The base class for drawing a bitmap image from the SD card onscreen. You must include the SD library to use PImage. 1022 | 1023 | #### Syntax 1024 | 1025 | ``` 1026 | PImage image; 1027 | 1028 | ``` 1029 | 1030 | #### Parameters 1031 | image : the name of the PImage object. You'll refer to this when drawing images on screen. 1032 | 1033 | #### Returns 1034 | none 1035 | 1036 | #### Example 1037 | 1038 | ``` 1039 | // this example looks for a file named "logo.bmp" 1040 | // on the SD card, and renders it to the screen 1041 | #include 1042 | #include 1043 | #include 1044 | #include // Arduino TFT library 1045 | 1046 | #define SD_CS 8 // Chip select line for SD card in Esplora 1047 | 1048 | PImage logo; 1049 | 1050 | void setup() { 1051 | // initialize the screen 1052 | EsploraTFT.begin(); 1053 | // initialize the SD card 1054 | SD.begin(SD_CS); 1055 | // set the background the black 1056 | EsploraTFT.background(0, 0, 0); 1057 | 1058 | // load the image into the named instance of PImage 1059 | logo = EsploraTFT.loadImage("arduino.bmp"); 1060 | 1061 | // if it is a valid image file, turn the Esplora's LED green 1062 | if (logo.isValid()) { 1063 | Esplora.writeGreen(255); 1064 | } 1065 | else{ 1066 | // if it is not valid, turn the LED red 1067 | Esplora.writeRed(255); 1068 | } 1069 | 1070 | // draw the image on the screen starting at the top left corner 1071 | EsploraTFT.image(logo, 0, 0); 1072 | 1073 | } 1074 | 1075 | void loop() { 1076 | 1077 | } 1078 | 1079 | ``` 1080 | 1081 | ### `PImage.height()` 1082 | 1083 | #### Description 1084 | 1085 | Checks the height of the PImage object. 1086 | 1087 | #### Syntax 1088 | 1089 | ``` 1090 | image.height(); 1091 | 1092 | ``` 1093 | 1094 | #### Parameters 1095 | none 1096 | 1097 | #### Returns 1098 | int : the image's height in pixels 1099 | 1100 | #### Example 1101 | 1102 | ``` 1103 | // this example looks for a file named "logo.bmp" 1104 | // on the SD card, and renders it to the screen 1105 | #include 1106 | #include 1107 | #include 1108 | #include // Arduino TFT library 1109 | 1110 | #define SD_CS 8 // Chip select line for SD card in Esplora 1111 | 1112 | PImage logo; 1113 | 1114 | void setup() { 1115 | // initialize the screen 1116 | EsploraTFT.begin(); 1117 | // initialize the SD card 1118 | SD.begin(SD_CS); 1119 | // set the background the black 1120 | EsploraTFT.background(0, 0, 0); 1121 | 1122 | // load the image into the named instance of PImage 1123 | logo = EsploraTFT.loadImage("arduino.bmp"); 1124 | 1125 | // if it is a valid image file, turn the Esplora's LED green 1126 | if (logo.isValid()) { 1127 | Esplora.writeGreen(255); 1128 | } 1129 | else{ 1130 | // if it is not valid, turn the LED red 1131 | Esplora.writeRed(255); 1132 | } 1133 | 1134 | 1135 | } 1136 | 1137 | void loop() { 1138 | // randomly draw the image on screen 1139 | int x = random(EsploraTFT.width() - logo.width()); 1140 | int y = random(EsploraTFT.height() - logo.height()); 1141 | EsploraTFT.image(logo, x, y); 1142 | delay(1500); 1143 | 1144 | } 1145 | 1146 | ``` 1147 | 1148 | ### `PImage.width()` 1149 | 1150 | #### Description 1151 | 1152 | Checks the width of the PImage object. 1153 | 1154 | #### Syntax 1155 | 1156 | ``` 1157 | image.width(); 1158 | 1159 | ``` 1160 | 1161 | #### Parameters 1162 | none 1163 | 1164 | #### Returns 1165 | int : the image's width in pixels 1166 | 1167 | #### Example 1168 | 1169 | ``` 1170 | // this example looks for a file named "logo.bmp" 1171 | // on the SD card, and renders it to the screen 1172 | #include 1173 | #include 1174 | #include 1175 | #include // Arduino TFT library 1176 | 1177 | #define SD_CS 8 // Chip select line for SD card in Esplora 1178 | 1179 | PImage logo; 1180 | 1181 | void setup() { 1182 | // initialize the screen 1183 | EsploraTFT.begin(); 1184 | // initialize the SD card 1185 | SD.begin(SD_CS); 1186 | // set the background the black 1187 | EsploraTFT.background(0, 0, 0); 1188 | 1189 | // load the image into the named instance of PImage 1190 | logo = EsploraTFT.loadImage("arduino.bmp"); 1191 | 1192 | // if it is a valid image file, turn the Esplora's LED green 1193 | if (logo.isValid()) { 1194 | Esplora.writeGreen(255); 1195 | } 1196 | else{ 1197 | // if it is not valid, turn the LED red 1198 | Esplora.writeRed(255); 1199 | } 1200 | 1201 | 1202 | } 1203 | 1204 | void loop() { 1205 | // randomly draw the image on screen 1206 | int x = random(EsploraTFT.width() - logo.width()); 1207 | int y = random(EsploraTFT.height() - logo.height()); 1208 | EsploraTFT.image(logo, x, y); 1209 | delay(1500); 1210 | 1211 | } 1212 | 1213 | ``` 1214 | 1215 | ### `PImage.isValid()` 1216 | 1217 | #### Description 1218 | 1219 | Checks if a named instance of PImage references a valid bitmap file. 1220 | 1221 | #### Syntax 1222 | 1223 | ``` 1224 | image.isValid(); 1225 | 1226 | ``` 1227 | 1228 | #### Parameters 1229 | none 1230 | 1231 | #### Returns 1232 | boolean 1233 | 1234 | #### Example 1235 | 1236 | ``` 1237 | // this example looks for a file named "logo.bmp" 1238 | // on the SD card, and renders it to the screen 1239 | #include 1240 | #include 1241 | #include 1242 | #include // Arduino TFT library 1243 | 1244 | #define SD_CS 8 // Chip select line for SD card in Esplora 1245 | 1246 | PImage logo; 1247 | 1248 | void setup() { 1249 | // initialize the screen 1250 | EsploraTFT.begin(); 1251 | // initialize the SD card 1252 | SD.begin(SD_CS); 1253 | // set the background the black 1254 | EsploraTFT.background(0, 0, 0); 1255 | 1256 | // load the image into the named instance of PImage 1257 | logo = EsploraTFT.loadImage("arduino.bmp"); 1258 | 1259 | // if it is a valid image file, turn the Esplora's LED green 1260 | if (logo.isValid()) { 1261 | Esplora.writeGreen(255); 1262 | } 1263 | else{ 1264 | // if it is not valid, turn the LED red 1265 | Esplora.writeRed(255); 1266 | } 1267 | 1268 | // draw the image on the screen starting at the top left corner 1269 | EsploraTFT.image(logo, 0, 0); 1270 | 1271 | } 1272 | 1273 | void loop() { 1274 | 1275 | } 1276 | 1277 | ``` -------------------------------------------------------------------------------- /docs/readme.md: -------------------------------------------------------------------------------- 1 | # TFT LCD library 2 | 3 | The TFT library is included with [Arduino IDE 1.0.5](https://www.arduino.cc/en/software) and later. 4 | 5 | This library enables an Arduino board to communicate with the [Arduino TFT LCD screen](https://docs.arduino.cc/retired/other/arduino-lcd-screen). It simplifies the process for drawing shapes, lines, images, and text to the screen. 6 | 7 | The Arduino TFT library extends the [Adafruit GFX](https://github.com/adafruit/Adafruit-GFX-Library), and [Adafruit ST7735](https://github.com/adafruit/Adafruit-ST7735-Library) libraries that it is based on. The GFX library is responsible for the drawing routines, while the ST7735 library is specific to the screen on the Arduino TFT. The Arduino specific additions were designed to work as similarly to the Processing API as possible. 8 | 9 | Onboard the screen is a SD card slot, which can be used through the [SD library](https://www.arduino.cc/en/Reference/SD). 10 | 11 | The TFT library relies on the [SPI library](https://www.arduino.cc/en/Reference/SPI) for communication with the screen and SD card, and needs to be included in all sketches. 12 | 13 | To use this library: 14 | 15 | ``` 16 | #include 17 | #include 18 | ``` 19 | 20 | ## Using the Library 21 | 22 | The screen can be configured for use in two ways. One is to use an Arduino's hardware SPI interface. The other is to declare all the pins manually. There is no difference in the functionality of the screen between the two methods, but using hardware SPI is significantly faster. 23 | 24 | If you plan on using the SD card on the TFT module, you must use hardware SPI. All examples in the library are written for hardware SPI use. 25 | 26 | If using hardware SPI with the Uno, you only need to declare the CS, DC, and RESET pins, as MOSI (pin 11) and SCLK (pin 13) are already defined. 27 | 28 | ``` 29 | #define CS 10 30 | #define DC 9 31 | #define RESET 8 32 | 33 | TFT myScreen = TFT(CS, DC, RESET); 34 | ``` 35 | 36 | To use hardware SPI with the Leonardo, you declare the pins like so : 37 | 38 | ``` 39 | #define CS 7 40 | #define DC 0 41 | #define RESET 1 42 | 43 | TFT myScreen = TFT(CS, DC, RESET); 44 | ``` 45 | 46 | When not using hardware SPI, you can use any available pins, but you must declare the MOSI and SCLK pins in addition to CD, DC, and RESET. 47 | 48 | ``` 49 | #define SCLK 4 50 | #define MOSI 5 51 | #define CS 6 52 | #define DC 7 53 | #define RESET 8 54 | 55 | TFT myScreen = TFT(CS, DC, MOSI, SCLK, RESET); 56 | ``` 57 | 58 | 59 | ## Using the Arduino Esplora and the TFT library 60 | 61 | As the Arduino Esplora has a socket designed for the TFT, and the pins for using the screen are fixed, an Esplora only object is created when targeting sketches for that board. You can reference the screen attached to an Esplora through `EsploraTFT`. 62 | 63 | ## Similarities to Processing 64 | 65 | [Processing](https://processing.org/) is an open source software environment used by designers, artists, and students. The main output of Processing is a graphic window on a computer or browser. The Arduino TFT library has made the calls for drawing primitives and text to the screen as "Processing-like" as possible to ensure a smooth transition between the two environments. 66 | 67 | ## Examples 68 | 69 | You can find examples for this library (both Arduino and Esplora specific examples) at the [Examples from Libraries page](https://docs.arduino.cc/library-examples). -------------------------------------------------------------------------------- /examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Arduino TFT Bitmap Logo example 4 | 5 | This example reads an image file from a micro-SD card 6 | and draws it on the screen, at random locations. 7 | 8 | In this sketch, the Arduino logo is read from a micro-SD card. 9 | There is a .bmp file included with this sketch. 10 | - open the sketch folder (Ctrl-K or Cmd-K) 11 | - copy the "arduino.bmp" file to a micro-SD 12 | - put the SD into the SD slot of the Arduino TFT module. 13 | 14 | This example code is in the public domain. 15 | 16 | Created 19 April 2013 by Enrico Gueli 17 | 18 | https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTBitmapLogo 19 | 20 | */ 21 | 22 | // include the necessary libraries 23 | #include 24 | #include 25 | #include // Arduino LCD library 26 | 27 | // pin definitions for the Uno 28 | #define sd_cs 4 29 | #define lcd_cs 10 30 | #define dc 9 31 | #define rst 8 32 | 33 | // pin definitions for the Leonardo 34 | //#define sd_cs 8 35 | //#define lcd_cs 7 36 | //#define dc 0 37 | //#define rst 1 38 | 39 | TFT TFTscreen = TFT(lcd_cs, dc, rst); 40 | 41 | // this variable represents the image to be drawn on screen 42 | PImage logo; 43 | 44 | 45 | void setup() { 46 | // initialize the GLCD and show a message 47 | // asking the user to open the serial line 48 | TFTscreen.begin(); 49 | TFTscreen.background(255, 255, 255); 50 | 51 | TFTscreen.stroke(0, 0, 255); 52 | TFTscreen.println(); 53 | TFTscreen.println(F("Arduino TFT Bitmap Example")); 54 | TFTscreen.stroke(0, 0, 0); 55 | TFTscreen.println(F("Open Serial Monitor")); 56 | TFTscreen.println(F("to run the sketch")); 57 | 58 | // initialize the serial port: it will be used to 59 | // print some diagnostic info 60 | Serial.begin(9600); 61 | while (!Serial) { 62 | // wait for serial port to connect. Needed for native USB port only 63 | } 64 | 65 | // clear the GLCD screen before starting 66 | TFTscreen.background(255, 255, 255); 67 | 68 | // try to access the SD card. If that fails (e.g. 69 | // no card present), the setup process will stop. 70 | Serial.print(F("Initializing SD card...")); 71 | if (!SD.begin(sd_cs)) { 72 | Serial.println(F("failed!")); 73 | return; 74 | } 75 | Serial.println(F("OK!")); 76 | 77 | // initialize and clear the GLCD screen 78 | TFTscreen.begin(); 79 | TFTscreen.background(255, 255, 255); 80 | 81 | // now that the SD card can be accessed, try to load the 82 | // image file. 83 | logo = TFTscreen.loadImage("arduino.bmp"); 84 | if (!logo.isValid()) { 85 | Serial.println(F("error while loading arduino.bmp")); 86 | } 87 | } 88 | 89 | void loop() { 90 | // don't do anything if the image wasn't loaded correctly. 91 | if (logo.isValid() == false) { 92 | return; 93 | } 94 | 95 | Serial.println(F("drawing image")); 96 | 97 | // get a random location to draw the image at. 98 | // To avoid the image being drawn outside the screen, 99 | // take into account the image size. 100 | int x = random(TFTscreen.width() - logo.width()); 101 | int y = random(TFTscreen.height() - logo.height()); 102 | 103 | // draw the image to the screen 104 | TFTscreen.image(logo, x, y); 105 | 106 | // wait a little bit before drawing again 107 | delay(1500); 108 | } 109 | -------------------------------------------------------------------------------- /examples/Arduino/TFTBitmapLogo/arduino.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/TFT/3302edafdc5470a32459aa40e2107bc40b9f92d1/examples/Arduino/TFTBitmapLogo/arduino.bmp -------------------------------------------------------------------------------- /examples/Arduino/TFTColorPicker/TFTColorPicker.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | TFT Color Picker 4 | 5 | This example for the Arduino screen reads the input of 6 | potentiometers or analog sensors attached to A0, A1, 7 | and A2 and uses the values to change the screen's color. 8 | 9 | This example code is in the public domain. 10 | 11 | Created 15 April 2013 by Scott Fitzgerald 12 | 13 | https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTColorPicker 14 | 15 | */ 16 | 17 | // pin definitions for the Uno 18 | #define cs 10 19 | #define dc 9 20 | #define rst 8 21 | 22 | // pin definitions for the Leonardo 23 | // #define cs 7 24 | // #define dc 0 25 | // #define rst 1 26 | 27 | #include // Arduino LCD library 28 | #include 29 | 30 | TFT TFTscreen = TFT(cs, dc, rst); 31 | 32 | void setup() { 33 | // begin serial communication 34 | Serial.begin(9600); 35 | 36 | // initialize the display 37 | TFTscreen.begin(); 38 | 39 | // set the background to white 40 | TFTscreen.background(255, 255, 255); 41 | 42 | } 43 | 44 | void loop() { 45 | 46 | // read the values from your sensors and scale them to 0-255 47 | int redVal = map(analogRead(A0), 0, 1023, 0, 255); 48 | int greenVal = map(analogRead(A1), 0, 1023, 0, 255); 49 | int blueVal = map(analogRead(A2), 0, 1023, 0, 255); 50 | 51 | // draw the background based on the mapped values 52 | TFTscreen.background(redVal, greenVal, blueVal); 53 | 54 | // send the values to the Serial Monitor 55 | Serial.print("background("); 56 | Serial.print(redVal); 57 | Serial.print(" , "); 58 | Serial.print(greenVal); 59 | Serial.print(" , "); 60 | Serial.print(blueVal); 61 | Serial.println(")"); 62 | 63 | // wait for a moment 64 | delay(33); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /examples/Arduino/TFTDisplayText/TFTDisplayText.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino TFT text example 3 | 4 | This example demonstrates how to draw text on the 5 | TFT with an Arduino. The Arduino reads the value 6 | of an analog sensor attached to pin A0, and writes 7 | the value to the LCD screen, updating every 8 | quarter second. 9 | 10 | This example code is in the public domain 11 | 12 | Created 15 April 2013 by Scott Fitzgerald 13 | 14 | https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTDisplayText 15 | 16 | */ 17 | 18 | #include // Arduino LCD library 19 | #include 20 | 21 | // pin definitions for the Uno 22 | #define cs 10 23 | #define dc 9 24 | #define rst 8 25 | 26 | // pin definitions for the Leonardo 27 | // #define cs 7 28 | // #define dc 0 29 | // #define rst 1 30 | 31 | // create an instance of the library 32 | TFT TFTscreen = TFT(cs, dc, rst); 33 | 34 | // char array to print to the screen 35 | char sensorPrintout[4]; 36 | 37 | void setup() { 38 | 39 | // Put this line at the beginning of every sketch that uses the GLCD: 40 | TFTscreen.begin(); 41 | 42 | // clear the screen with a black background 43 | TFTscreen.background(0, 0, 0); 44 | 45 | // write the static text to the screen 46 | // set the font color to white 47 | TFTscreen.stroke(255, 255, 255); 48 | // set the font size 49 | TFTscreen.setTextSize(2); 50 | // write the text to the top left corner of the screen 51 | TFTscreen.text("Sensor Value :\n ", 0, 0); 52 | // set the font size very large for the loop 53 | TFTscreen.setTextSize(5); 54 | } 55 | 56 | void loop() { 57 | 58 | // Read the value of the sensor on A0 59 | String sensorVal = String(analogRead(A0)); 60 | 61 | // convert the reading to a char array 62 | sensorVal.toCharArray(sensorPrintout, 4); 63 | 64 | // set the font color 65 | TFTscreen.stroke(255, 255, 255); 66 | // print the sensor value 67 | TFTscreen.text(sensorPrintout, 0, 20); 68 | // wait for a moment 69 | delay(250); 70 | // erase the text you just wrote 71 | TFTscreen.stroke(0, 0, 0); 72 | TFTscreen.text(sensorPrintout, 0, 20); 73 | } 74 | -------------------------------------------------------------------------------- /examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | TFT EtchASketch 4 | 5 | This example for the Arduino screen draws a white point 6 | on the GLCD based on the values of 2 potentiometers. 7 | To clear the screen, press a button attached to pin 2. 8 | 9 | This example code is in the public domain. 10 | 11 | Created 15 April 2013 by Scott Fitzgerald 12 | 13 | https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTEtchASketch 14 | 15 | */ 16 | 17 | #include // Arduino LCD library 18 | #include 19 | 20 | // pin definitions for the Uno 21 | #define cs 10 22 | #define dc 9 23 | #define rst 8 24 | 25 | // pin definitions for the Leonardo 26 | // #define cs 7 27 | // #define dc 0 28 | // #define rst 1 29 | 30 | TFT TFTscreen = TFT(cs, dc, rst); 31 | 32 | // initial position of the cursor 33 | int xPos = TFTscreen.width() / 2; 34 | int yPos = TFTscreen.height() / 2; 35 | 36 | // pin the erase switch is connected to 37 | int erasePin = 2; 38 | 39 | void setup() { 40 | // declare inputs 41 | pinMode(erasePin, INPUT); 42 | // initialize the screen 43 | TFTscreen.begin(); 44 | // make the background black 45 | TFTscreen.background(0, 0, 0); 46 | } 47 | 48 | void loop() { 49 | // read the potentiometers on A0 and A1 50 | int xValue = analogRead(A0); 51 | int yValue = analogRead(A1); 52 | 53 | // map the values and update the position 54 | xPos = xPos + (map(xValue, 0, 1023, 2, -2)); 55 | yPos = yPos + (map(yValue, 0, 1023, -2, 2)); 56 | 57 | // don't let the point go past the screen edges 58 | if (xPos > 159) { 59 | (xPos = 159); 60 | } 61 | 62 | if (xPos < 0) { 63 | (xPos = 0); 64 | } 65 | if (yPos > 127) { 66 | (yPos = 127); 67 | } 68 | 69 | if (yPos < 0) { 70 | (yPos = 0); 71 | } 72 | 73 | // draw the point 74 | TFTscreen.stroke(255, 255, 255); 75 | TFTscreen.point(xPos, yPos); 76 | 77 | // read the value of the pin, and erase the screen if pressed 78 | if (digitalRead(erasePin) == HIGH) { 79 | TFTscreen.background(0, 0, 0); 80 | } 81 | 82 | delay(33); 83 | } 84 | -------------------------------------------------------------------------------- /examples/Arduino/TFTGraph/TFTGraph.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | TFT Graph 4 | 5 | This example for an Arduino screen reads 6 | the value of an analog sensor on A0, and 7 | graphs the values on the screen. 8 | 9 | This example code is in the public domain. 10 | 11 | Created 15 April 2013 by Scott Fitzgerald 12 | 13 | https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTGraph 14 | 15 | */ 16 | 17 | #include // Arduino LCD library 18 | #include 19 | 20 | // pin definitions for the Uno 21 | #define cs 10 22 | #define dc 9 23 | #define rst 8 24 | 25 | // pin definitions for the Leonardo 26 | // #define cs 7 27 | // #define dc 0 28 | // #define rst 1 29 | 30 | TFT TFTscreen = TFT(cs, dc, rst); 31 | 32 | // position of the line on screen 33 | int xPos = 0; 34 | 35 | void setup() { 36 | // initialize the serial port 37 | Serial.begin(9600); 38 | 39 | // initialize the display 40 | TFTscreen.begin(); 41 | 42 | // clear the screen with a pretty color 43 | TFTscreen.background(250, 16, 200); 44 | } 45 | 46 | void loop() { 47 | // read the sensor and map it to the screen height 48 | int sensor = analogRead(A0); 49 | int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height()); 50 | 51 | // print out the height to the Serial Monitor 52 | Serial.println(drawHeight); 53 | 54 | // draw a line in a nice color 55 | TFTscreen.stroke(250, 180, 10); 56 | TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height()); 57 | 58 | // if the graph has reached the screen edge 59 | // erase the screen and start again 60 | if (xPos >= 160) { 61 | xPos = 0; 62 | TFTscreen.background(250, 16, 200); 63 | } else { 64 | // increment the horizontal position: 65 | xPos++; 66 | } 67 | 68 | delay(16); 69 | } 70 | -------------------------------------------------------------------------------- /examples/Arduino/TFTPong/TFTPong.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | TFT Pong 4 | 5 | This example for the Arduino screen reads the values 6 | of 2 potentiometers to move a rectangular platform 7 | on the x and y axes. The platform can intersect 8 | with a ball causing it to bounce. 9 | 10 | This example code is in the public domain. 11 | 12 | Created by Tom Igoe December 2012 13 | Modified 15 April 2013 by Scott Fitzgerald 14 | 15 | https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTPong 16 | 17 | */ 18 | 19 | #include // Arduino LCD library 20 | #include 21 | 22 | // pin definitions for the Uno 23 | #define cs 10 24 | #define dc 9 25 | #define rst 8 26 | 27 | // pin definitions for the Leonardo 28 | // #define cs 7 29 | // #define dc 0 30 | // #define rst 1 31 | 32 | TFT TFTscreen = TFT(cs, dc, rst); 33 | 34 | // variables for the position of the ball and paddle 35 | int paddleX = 0; 36 | int paddleY = 0; 37 | int oldPaddleX, oldPaddleY; 38 | int ballDirectionX = 1; 39 | int ballDirectionY = 1; 40 | 41 | int ballSpeed = 10; // lower numbers are faster 42 | 43 | int ballX, ballY, oldBallX, oldBallY; 44 | 45 | void setup() { 46 | // initialize the display 47 | TFTscreen.begin(); 48 | // black background 49 | TFTscreen.background(0, 0, 0); 50 | } 51 | 52 | void loop() { 53 | 54 | // save the width and height of the screen 55 | int myWidth = TFTscreen.width(); 56 | int myHeight = TFTscreen.height(); 57 | 58 | // map the paddle's location to the position of the potentiometers 59 | paddleX = map(analogRead(A0), 512, -512, 0, myWidth) - 20 / 2; 60 | paddleY = map(analogRead(A1), 512, -512, 0, myHeight) - 5 / 2; 61 | 62 | // set the fill color to black and erase the previous 63 | // position of the paddle if different from present 64 | TFTscreen.fill(0, 0, 0); 65 | 66 | if (oldPaddleX != paddleX || oldPaddleY != paddleY) { 67 | TFTscreen.rect(oldPaddleX, oldPaddleY, 20, 5); 68 | } 69 | 70 | // draw the paddle on screen, save the current position 71 | // as the previous. 72 | TFTscreen.fill(255, 255, 255); 73 | 74 | TFTscreen.rect(paddleX, paddleY, 20, 5); 75 | oldPaddleX = paddleX; 76 | oldPaddleY = paddleY; 77 | 78 | // update the ball's position and draw it on screen 79 | if (millis() % ballSpeed < 2) { 80 | moveBall(); 81 | } 82 | } 83 | 84 | // this function determines the ball's position on screen 85 | void moveBall() { 86 | // if the ball goes offscreen, reverse the direction: 87 | if (ballX > TFTscreen.width() || ballX < 0) { 88 | ballDirectionX = -ballDirectionX; 89 | } 90 | 91 | if (ballY > TFTscreen.height() || ballY < 0) { 92 | ballDirectionY = -ballDirectionY; 93 | } 94 | 95 | // check if the ball and the paddle occupy the same space on screen 96 | if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { 97 | ballDirectionX = -ballDirectionX; 98 | ballDirectionY = -ballDirectionY; 99 | } 100 | 101 | // update the ball's position 102 | ballX += ballDirectionX; 103 | ballY += ballDirectionY; 104 | 105 | // erase the ball's previous position 106 | TFTscreen.fill(0, 0, 0); 107 | 108 | if (oldBallX != ballX || oldBallY != ballY) { 109 | TFTscreen.rect(oldBallX, oldBallY, 5, 5); 110 | } 111 | 112 | 113 | // draw the ball's current position 114 | TFTscreen.fill(255, 255, 255); 115 | TFTscreen.rect(ballX, ballY, 5, 5); 116 | 117 | oldBallX = ballX; 118 | oldBallY = ballY; 119 | 120 | } 121 | 122 | // this function checks the position of the ball 123 | // to see if it intersects with the paddle 124 | bool inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { 125 | bool result = false; 126 | 127 | if ((x >= rectX && x <= (rectX + rectWidth)) && 128 | (y >= rectY && y <= (rectY + rectHeight))) { 129 | result = true; 130 | } 131 | 132 | return result; 133 | } 134 | -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Esplora TFT Bitmap Logos 4 | 5 | This example for the Arduino TFT screen is for use 6 | with an Arduino Esplora. 7 | 8 | This example reads an image file from a micro-SD card 9 | and draws it on the screen, at random locations. 10 | 11 | There is a .bmp file included with this sketch. 12 | - open the sketch folder (Ctrl-K or Cmd-K) 13 | - copy the "arduino.bmp" file to a micro-SD 14 | - put the SD into the SD slot of the Arduino LCD module. 15 | 16 | This example code is in the public domain. 17 | 18 | Created 19 April 2013 by Enrico Gueli 19 | 20 | https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTBitmapLogo 21 | 22 | */ 23 | 24 | // include the necessary libraries 25 | #include 26 | #include 27 | #include 28 | #include // Arduino LCD library 29 | 30 | // the Esplora pin connected to the chip select line for SD card 31 | #define SD_CS 8 32 | 33 | // this variable represents the image to be drawn on screen 34 | PImage logo; 35 | 36 | void setup() { 37 | // initialize the GLCD and show a message 38 | // asking the user to open the serial line 39 | EsploraTFT.begin(); 40 | EsploraTFT.background(255, 255, 255); 41 | 42 | EsploraTFT.stroke(0, 0, 255); 43 | EsploraTFT.println(); 44 | EsploraTFT.println(F("Arduino LCD Bitmap Example")); 45 | EsploraTFT.stroke(0, 0, 0); 46 | EsploraTFT.println(F("Open Serial Monitor")); 47 | EsploraTFT.println(F("to run the sketch")); 48 | 49 | // initialize the serial port: it will be used to 50 | // print some diagnostic info 51 | Serial.begin(9600); 52 | while (!Serial) { 53 | // wait for serial port to connect. Needed for native USB port only 54 | } 55 | 56 | // try to access the SD card. If that fails (e.g. 57 | // no card present), the Esplora's LED will turn red. 58 | Serial.print(F("Initializing SD card...")); 59 | if (!SD.begin(SD_CS)) { 60 | Serial.println(F("failed!")); 61 | Esplora.writeRed(255); 62 | return; 63 | } 64 | Serial.println("OK!"); 65 | 66 | // clear the GLCD screen before starting 67 | EsploraTFT.background(255, 255, 255); 68 | 69 | // now that the SD card can be accessed, try to load the 70 | // image file. The Esplora LED will turn green or red if 71 | // the loading went OK or not. 72 | Esplora.writeRGB(0, 0, 0); 73 | logo = EsploraTFT.loadImage("arduino.bmp"); 74 | if (logo.isValid()) { 75 | Esplora.writeGreen(255); 76 | } else { 77 | Esplora.writeRed(255); 78 | } 79 | 80 | } 81 | 82 | void loop() { 83 | // don't do anything if the image wasn't loaded correctly. 84 | if (logo.isValid() == false) { 85 | return; 86 | } 87 | 88 | Serial.println(F("drawing image")); 89 | 90 | // get a random location to draw the image at. 91 | // To avoid the image being drawn outside the screen, 92 | // take into account the image size. 93 | int x = random(EsploraTFT.width() - logo.width()); 94 | int y = random(EsploraTFT.height() - logo.height()); 95 | 96 | // draw the image to the screen 97 | EsploraTFT.image(logo, x, y); 98 | 99 | // wait a little bit before drawing again 100 | delay(1500); 101 | } 102 | -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTBitmapLogo/arduino.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/TFT/3302edafdc5470a32459aa40e2107bc40b9f92d1/examples/Esplora/EsploraTFTBitmapLogo/arduino.bmp -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Esplora TFT Color Picker 4 | 5 | This example for the Esplora with an Arduino TFT reads 6 | the input of the joystick and slider, using the values 7 | to change the screen's color. 8 | 9 | This example code is in the public domain. 10 | 11 | Created 15 April 2013 by Scott Fitzgerald 12 | 13 | https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTColorPicker 14 | 15 | */ 16 | 17 | #include 18 | #include // Arduino LCD library 19 | #include 20 | 21 | void setup() { 22 | Serial.begin(9600); 23 | 24 | // initialize the LCD 25 | EsploraTFT.begin(); 26 | 27 | // start out with a white screen 28 | EsploraTFT.background(255, 255, 255); 29 | 30 | } 31 | 32 | void loop() { 33 | 34 | // map the values from sensors 35 | int xValue = map(Esplora.readJoystickX(), -512, 512, 0, 255); // read the joystick's X position 36 | int yValue = map(Esplora.readJoystickY(), -512, 512, 0, 255); // read the joystick's Y position 37 | int slider = map(Esplora.readSlider(), 0, 1023, 0, 255); // read the slider's position 38 | 39 | // change the background color based on the mapped values 40 | EsploraTFT.background(xValue, yValue, slider); 41 | 42 | // print the mapped values to the Serial Monitor 43 | Serial.print("background("); 44 | Serial.print(xValue); 45 | Serial.print(" , "); 46 | Serial.print(yValue); 47 | Serial.print(" , "); 48 | Serial.print(slider); 49 | Serial.println(")"); 50 | 51 | delay(33); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Esplora TFT EtchASketch 4 | 5 | This example for the Arduino TFT and Esplora draws 6 | a white line on the screen, based on the position 7 | of the joystick. To clear the screen, shake the 8 | Esplora, using the values from the accelerometer. 9 | 10 | This example code is in the public domain. 11 | 12 | Created 15 April 2013 by Scott Fitzgerald 13 | 14 | https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTEtchASketch 15 | 16 | */ 17 | 18 | #include 19 | #include // Arduino LCD library 20 | #include 21 | 22 | // initial position of the cursor 23 | int xPos = EsploraTFT.width() / 2; 24 | int yPos = EsploraTFT.height() / 2; 25 | 26 | void setup() { 27 | // initialize the display 28 | EsploraTFT.begin(); 29 | 30 | // clear the background 31 | EsploraTFT.background(0, 0, 0); 32 | } 33 | 34 | void loop() { 35 | 36 | int xAxis = Esplora.readJoystickX(); // read the X axis 37 | int yAxis = Esplora.readJoystickY(); // read the Y axis 38 | 39 | // update the position of the line 40 | // depending on the position of the joystick 41 | if (xAxis < 10 && xAxis > -10) { 42 | xPos = xPos; 43 | } else { 44 | xPos = xPos + (map(xAxis, -512, 512, 2, -2)); 45 | } 46 | if (yAxis < 10 && yAxis > -10) { 47 | yAxis = yAxis; 48 | } else { 49 | yPos = yPos + (map(yAxis, -512, 512, -2, 2)); 50 | } 51 | 52 | // don't let the point go past the screen edges 53 | if (xPos > 159) { 54 | (xPos = 159); 55 | } 56 | 57 | if (xPos < 0) { 58 | (xPos = 0); 59 | } 60 | if (yPos > 127) { 61 | (yPos = 127); 62 | } 63 | 64 | if (yPos < 0) { 65 | (yPos = 0); 66 | } 67 | 68 | // draw the point 69 | EsploraTFT.stroke(255, 255, 255); 70 | EsploraTFT.point(xPos, yPos); 71 | 72 | // check the accelerometer values and clear 73 | // the screen if it is being shaken 74 | if (abs(Esplora.readAccelerometer(X_AXIS)) > 200 || abs(Esplora.readAccelerometer(Y_AXIS)) > 200) { 75 | EsploraTFT.background(0, 0, 0); 76 | } 77 | 78 | delay(33); 79 | } 80 | -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Esplora TFT Graph 4 | 5 | This example for the Esplora with an Arduino TFT reads 6 | the value of the light sensor, and graphs the values on 7 | the screen. 8 | 9 | This example code is in the public domain. 10 | 11 | Created 15 April 2013 by Scott Fitzgerald 12 | 13 | https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTGraph 14 | 15 | */ 16 | 17 | #include 18 | #include // Arduino LCD library 19 | #include 20 | 21 | // position of the line on screen 22 | int xPos = 0; 23 | 24 | void setup() { 25 | 26 | // initialize the screen 27 | EsploraTFT.begin(); 28 | 29 | // clear the screen with a nice color 30 | EsploraTFT.background(250, 16, 200); 31 | } 32 | 33 | void loop() { 34 | 35 | // read the sensor value 36 | int sensor = Esplora.readLightSensor(); 37 | // map the sensor value to the height of the screen 38 | int graphHeight = map(sensor, 0, 1023, 0, EsploraTFT.height()); 39 | 40 | // draw the line in a pretty color 41 | EsploraTFT.stroke(250, 180, 10); 42 | EsploraTFT.line(xPos, EsploraTFT.height() - graphHeight, xPos, EsploraTFT.height()); 43 | 44 | // if the graph reaches the edge of the screen 45 | // erase it and start over from the other side 46 | if (xPos >= 160) { 47 | xPos = 0; 48 | EsploraTFT.background(250, 16, 200); 49 | } else { 50 | // increment the horizontal position: 51 | xPos++; 52 | } 53 | 54 | delay(16); 55 | } 56 | -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Esplora TFT Horizon 4 | 5 | This example for the Arduino TFT and Esplora draws 6 | a line on the screen that stays level with the ground 7 | as you tilt the Esplora side to side 8 | 9 | This example code is in the public domain. 10 | 11 | Created 15 April 2013 by Scott Fitzgerald 12 | 13 | https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTHorizon 14 | 15 | */ 16 | 17 | #include 18 | #include // Arduino LCD library 19 | #include 20 | 21 | // horizontal start and end positions 22 | int yStart = EsploraTFT.height() / 2; 23 | int yEnd = EsploraTFT.height() / 2; 24 | 25 | // previous start and end positions 26 | int oldEndY; 27 | int oldStartY; 28 | 29 | void setup() { 30 | // initialize the display 31 | EsploraTFT.begin(); 32 | // make the background black 33 | EsploraTFT.background(0, 0, 0); 34 | } 35 | 36 | void loop() { 37 | // read the x-axis of the accelerometer 38 | int tilt = Esplora.readAccelerometer(X_AXIS); 39 | 40 | // the values are 100 when tilted to the left 41 | // and -100 when tilted to the right 42 | // map these values to the start and end points 43 | yStart = map(tilt, -100, 100, EsploraTFT.height(), 0); 44 | yEnd = map(tilt, -100, 100, 0, EsploraTFT.height()); 45 | 46 | // if the previous values are different than the current values 47 | // erase the previous line 48 | if (oldStartY != yStart || oldEndY != yEnd) { 49 | EsploraTFT.stroke(0, 0, 0); 50 | EsploraTFT.line(0, oldStartY, EsploraTFT.width(), oldEndY); 51 | } 52 | 53 | // draw the line in magenta 54 | EsploraTFT.stroke(255, 0, 255); 55 | EsploraTFT.line(0, yStart, EsploraTFT.width(), yEnd); 56 | 57 | // save the current start and end points 58 | // to compare in the next loop 59 | oldStartY = yStart; 60 | oldEndY = yEnd; 61 | delay(10); 62 | } 63 | -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Esplora TFT Pong 4 | 5 | This example for the Esplora with an Arduino TFT screen reads 6 | the value of the joystick to move a rectangular platform 7 | on the x and y axes. The platform can intersect with a ball 8 | causing it to bounce. The Esplora's slider adjusts the speed 9 | of the ball. 10 | 11 | This example code is in the public domain. 12 | 13 | Created by Tom Igoe December 2012 14 | Modified 15 April 2013 by Scott Fitzgerald 15 | 16 | https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTPong 17 | 18 | */ 19 | 20 | #include 21 | #include // Arduino LCD library 22 | #include 23 | 24 | // variables for the position of the ball and paddle 25 | int paddleX = 0; 26 | int paddleY = 0; 27 | int oldPaddleX, oldPaddleY; 28 | int ballDirectionX = 1; 29 | int ballDirectionY = 1; 30 | 31 | int ballX, ballY, oldBallX, oldBallY; 32 | 33 | void setup() { 34 | 35 | Serial.begin(9600); 36 | 37 | // initialize the display 38 | EsploraTFT.begin(); 39 | // set the background to black 40 | EsploraTFT.background(0, 0, 0); 41 | } 42 | 43 | void loop() { 44 | // save the width and height of the screen 45 | int myWidth = EsploraTFT.width(); 46 | int myHeight = EsploraTFT.height(); 47 | 48 | // map the paddle's location to the joystick's position 49 | paddleX = map(Esplora.readJoystickX(), 512, -512, 0, myWidth) - 20 / 2; 50 | paddleY = map(Esplora.readJoystickY(), -512, 512, 0, myHeight) - 5 / 2; 51 | Serial.print(paddleX); 52 | Serial.print(" "); 53 | Serial.println(paddleY); 54 | 55 | // set the fill color to black and erase the previous 56 | // position of the paddle if different from present 57 | EsploraTFT.fill(0, 0, 0); 58 | 59 | if (oldPaddleX != paddleX || oldPaddleY != paddleY) { 60 | EsploraTFT.rect(oldPaddleX, oldPaddleY, 20, 5); 61 | } 62 | 63 | // draw the paddle on screen, save the current position 64 | // as the previous. 65 | EsploraTFT.fill(255, 255, 255); 66 | EsploraTFT.rect(paddleX, paddleY, 20, 5); 67 | oldPaddleX = paddleX; 68 | oldPaddleY = paddleY; 69 | 70 | // read the slider to determine the speed of the ball 71 | int ballSpeed = map(Esplora.readSlider(), 0, 1023, 0, 80) + 1; 72 | if (millis() % ballSpeed < 2) { 73 | moveBall(); 74 | } 75 | } 76 | 77 | 78 | // this function determines the ball's position on screen 79 | void moveBall() { 80 | // if the ball goes offscreen, reverse the direction: 81 | if (ballX > EsploraTFT.width() || ballX < 0) { 82 | ballDirectionX = -ballDirectionX; 83 | } 84 | 85 | if (ballY > EsploraTFT.height() || ballY < 0) { 86 | ballDirectionY = -ballDirectionY; 87 | } 88 | 89 | // check if the ball and the paddle occupy the same space on screen 90 | if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { 91 | ballDirectionY = -ballDirectionY; 92 | } 93 | 94 | // update the ball's position 95 | ballX += ballDirectionX; 96 | ballY += ballDirectionY; 97 | 98 | // erase the ball's previous position 99 | EsploraTFT.fill(0, 0, 0); 100 | 101 | if (oldBallX != ballX || oldBallY != ballY) { 102 | EsploraTFT.rect(oldBallX, oldBallY, 5, 5); 103 | } 104 | 105 | // draw the ball's current position 106 | EsploraTFT.fill(255, 255, 255); 107 | 108 | EsploraTFT.rect(ballX, ballY, 5, 5); 109 | 110 | oldBallX = ballX; 111 | oldBallY = ballY; 112 | 113 | } 114 | 115 | // this function checks the position of the ball 116 | // to see if it intersects with the paddle 117 | bool inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { 118 | bool result = false; 119 | 120 | if ((x >= rectX && x <= (rectX + rectWidth)) && 121 | (y >= rectY && y <= (rectY + rectHeight))) { 122 | result = true; 123 | } 124 | 125 | return result; 126 | } 127 | -------------------------------------------------------------------------------- /examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Esplora TFT Temperature Display 4 | 5 | This example for the Arduino TFT screen is for use 6 | with an Arduino Esplora. 7 | 8 | This example reads the temperature of the Esplora's 9 | on board thermisistor and displays it on an attached 10 | LCD screen, updating every second. 11 | 12 | This example code is in the public domain. 13 | 14 | Created 15 April 2013 by Scott Fitzgerald 15 | 16 | https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTTemp 17 | 18 | */ 19 | 20 | // include the necessary libraries 21 | #include 22 | #include // Arduino LCD library 23 | #include 24 | 25 | char tempPrintout[3]; // array to hold the temperature data 26 | 27 | void setup() { 28 | 29 | // Put this line at the beginning of every sketch that uses the GLCD 30 | EsploraTFT.begin(); 31 | 32 | // clear the screen with a black background 33 | EsploraTFT.background(0, 0, 0); 34 | 35 | // set the text color to magenta 36 | EsploraTFT.stroke(200, 20, 180); 37 | // set the text to size 2 38 | EsploraTFT.setTextSize(2); 39 | // start the text at the top left of the screen 40 | // this text is going to remain static 41 | EsploraTFT.text("Degrees in C :\n ", 0, 0); 42 | 43 | // set the text in the loop to size 5 44 | EsploraTFT.setTextSize(5); 45 | } 46 | 47 | void loop() { 48 | 49 | // read the temperature in Celsius and store it in a String 50 | String temperature = String(Esplora.readTemperature(DEGREES_C)); 51 | 52 | // convert the string to a char array 53 | temperature.toCharArray(tempPrintout, 3); 54 | 55 | // set the text color to white 56 | EsploraTFT.stroke(255, 255, 255); 57 | // print the temperature one line below the static text 58 | EsploraTFT.text(tempPrintout, 0, 30); 59 | 60 | delay(1000); 61 | // erase the text for the next loop 62 | EsploraTFT.stroke(0, 0, 0); 63 | EsploraTFT.text(tempPrintout, 0, 30); 64 | } 65 | -------------------------------------------------------------------------------- /extras/Adafruit-README.txt: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit 1.8" SPI display. 2 | This library works with the Adafruit 1.8" TFT Breakout w/SD card 3 | ----> http://www.adafruit.com/products/358 4 | as well as Adafruit raw 1.8" TFT display 5 | ----> http://www.adafruit.com/products/618 6 | 7 | Check out the links above for our tutorials and wiring diagrams. 8 | These displays use SPI to communicate, 4 or 5 pins are required 9 | to interface (RST is optional). 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_ST7735. Check that the Adafruit_ST7735 folder contains Adafruit_ST7735.cpp and Adafruit_ST7735. 18 | 19 | Place the Adafruit_ST7735 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE 20 | 21 | Also requires the Adafruit_GFX library for Arduino. 22 | -------------------------------------------------------------------------------- /extras/Adafruit-license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of the copyright holders nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /extras/README.md: -------------------------------------------------------------------------------- 1 | TFT Library 2 | ============ 3 | 4 | An Arduino library for the Arduino TFT LCD screen. 5 | 6 | This library enables an Arduino board to communicate with an Arduino TFT LCD screen. It simplifies the process for drawing shapes, lines, images, and text to the screen. 7 | The Arduino TFT library extends the Adafruit GFX, and Adafruit ST7735 libraries that it is based on. The GFX library is responsible for the drawing routines, while the ST7735 library is specific to the screen on the Arduino GTFT. The Arduino specific additions were designed to work as similarly to the Processing API as possible. 8 | 9 | Onboard the screen is a SD card slot, which can be used through the SD library. 10 | 11 | The TFT library relies on the SPI library for communication with the screen and SD card, and needs to be included in all sketches. 12 | 13 | https://github.com/adafruit/Adafruit-GFX-Library 14 | https://github.com/adafruit/Adafruit-ST7735-Library 15 | http://www.arduino.cc/en/Reference/SD 16 | http://www.arduino.cc/en/Reference/SPI 17 | 18 | http://www.arduino.cc/en/Reference/TFTLibrary -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For TFT 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | TFT KEYWORD1 TFTLibrary 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | 16 | ####################################### 17 | # Constants (LITERAL1) 18 | ####################################### 19 | 20 | EsploraTFT LITERAL1 21 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=TFT 2 | version=1.0.6 3 | author=Arduino, Adafruit 4 | maintainer=Arduino 5 | sentence=Allows drawing text, images, and shapes on the Arduino TFT graphical display. 6 | paragraph=This library is compatible with most of the TFT displays based on the ST7735 chipset. 7 | category=Display 8 | url=http://www.arduino.cc/en/Reference/TFTLibrary 9 | architectures=avr,sam,samd 10 | -------------------------------------------------------------------------------- /src/TFT.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Enrico Gueli All 2 | rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include "TFT.h" 33 | 34 | #if ARDUINO_AVR_ESPLORA 35 | TFT EsploraTFT(7, 0, 1); 36 | #endif 37 | 38 | TFT::TFT(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK, uint8_t RST) 39 | : Adafruit_ST7735(CS, RS, SID, SCLK, RST) 40 | { 41 | // as we already know the orientation (landscape, therefore rotated), 42 | // set default width and height without need to call begin() first. 43 | _width = ST7735_TFTHEIGHT; 44 | _height = ST7735_TFTWIDTH; 45 | } 46 | 47 | TFT::TFT(uint8_t CS, uint8_t RS, uint8_t RST) 48 | : Adafruit_ST7735(CS, RS, RST) 49 | { 50 | // as we already know the orientation (landscape, therefore rotated), 51 | // set default width and height without need to call begin() first. 52 | _width = ST7735_TFTHEIGHT; 53 | _height = ST7735_TFTWIDTH; 54 | } 55 | 56 | void TFT::begin() { 57 | //initR(INITR_REDTAB); 58 | initG(); 59 | setRotation(1); 60 | } 61 | -------------------------------------------------------------------------------- /src/TFT.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Enrico Gueli All 2 | rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef _ARDUINO_TFT_H 33 | #define _ARDUINO_TFT_H 34 | 35 | #include "Arduino.h" 36 | #include "utility/Adafruit_GFX.h" 37 | #include "utility/Adafruit_ST7735.h" 38 | 39 | /// The Arduino LCD is a ST7735-based device. 40 | /// By default, it is mounted horizontally. 41 | /// TFT class follows the convention of other 42 | /// Arduino library classes by adding a begin() method 43 | /// to be called in the setup() routine. 44 | /// @author Enrico Gueli 45 | class TFT : public Adafruit_ST7735 { 46 | public: 47 | TFT(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK, uint8_t RST); 48 | TFT(uint8_t CS, uint8_t RS, uint8_t RST); 49 | 50 | void begin(); 51 | }; 52 | 53 | /// Esplora boards have hard-wired connections with 54 | /// the Arduino LCD if mounted on the onboard connector. 55 | #if ARDUINO_AVR_ESPLORA // are we building for Esplora? 56 | extern TFT EsploraTFT; 57 | #endif 58 | 59 | #endif // _ARDUINO_TFT_H 60 | -------------------------------------------------------------------------------- /src/utility/Adafruit_GFX.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This is the core graphics library for all our displays, providing a common 3 | set of graphics primitives (points, lines, circles, etc.). It needs to be 4 | paired with a hardware-specific library for each display device we carry 5 | (to handle the lower-level functions). 6 | 7 | Adafruit invests time and resources providing this open source code, please 8 | support Adafruit & open-source hardware by purchasing products from Adafruit! 9 | 10 | Copyright (c) 2013 Adafruit Industries. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "Adafruit_GFX.h" 35 | #include "glcdfont.c" 36 | #ifdef __AVR__ 37 | #include 38 | #else 39 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 40 | #endif 41 | 42 | Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h) : 43 | WIDTH(w), HEIGHT(h) 44 | { 45 | _width = WIDTH; 46 | _height = HEIGHT; 47 | rotation = 0; 48 | cursor_y = cursor_x = 0; 49 | textsize = 1; 50 | textcolor = textbgcolor = 0xFFFF; 51 | wrap = true; 52 | } 53 | 54 | // draw a circle outline 55 | void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, 56 | uint16_t color) { 57 | int16_t f = 1 - r; 58 | int16_t ddF_x = 1; 59 | int16_t ddF_y = -2 * r; 60 | int16_t x = 0; 61 | int16_t y = r; 62 | 63 | drawPixel(x0, y0+r, color); 64 | drawPixel(x0, y0-r, color); 65 | drawPixel(x0+r, y0, color); 66 | drawPixel(x0-r, y0, color); 67 | 68 | while (x= 0) { 70 | y--; 71 | ddF_y += 2; 72 | f += ddF_y; 73 | } 74 | x++; 75 | ddF_x += 2; 76 | f += ddF_x; 77 | 78 | drawPixel(x0 + x, y0 + y, color); 79 | drawPixel(x0 - x, y0 + y, color); 80 | drawPixel(x0 + x, y0 - y, color); 81 | drawPixel(x0 - x, y0 - y, color); 82 | drawPixel(x0 + y, y0 + x, color); 83 | drawPixel(x0 - y, y0 + x, color); 84 | drawPixel(x0 + y, y0 - x, color); 85 | drawPixel(x0 - y, y0 - x, color); 86 | } 87 | } 88 | 89 | void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, 90 | int16_t r, uint8_t cornername, uint16_t color) { 91 | int16_t f = 1 - r; 92 | int16_t ddF_x = 1; 93 | int16_t ddF_y = -2 * r; 94 | int16_t x = 0; 95 | int16_t y = r; 96 | 97 | while (x= 0) { 99 | y--; 100 | ddF_y += 2; 101 | f += ddF_y; 102 | } 103 | x++; 104 | ddF_x += 2; 105 | f += ddF_x; 106 | if (cornername & 0x4) { 107 | drawPixel(x0 + x, y0 + y, color); 108 | drawPixel(x0 + y, y0 + x, color); 109 | } 110 | if (cornername & 0x2) { 111 | drawPixel(x0 + x, y0 - y, color); 112 | drawPixel(x0 + y, y0 - x, color); 113 | } 114 | if (cornername & 0x8) { 115 | drawPixel(x0 - y, y0 + x, color); 116 | drawPixel(x0 - x, y0 + y, color); 117 | } 118 | if (cornername & 0x1) { 119 | drawPixel(x0 - y, y0 - x, color); 120 | drawPixel(x0 - x, y0 - y, color); 121 | } 122 | } 123 | } 124 | 125 | void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, 126 | uint16_t color) 127 | { 128 | drawFastVLine(x0, y0-r, 2*r+1, color); 129 | fillCircleHelper(x0, y0, r, 3, 0, color); 130 | } 131 | 132 | // used to do circles and roundrects 133 | void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 134 | uint8_t cornername, int16_t delta, uint16_t color) 135 | { 136 | int16_t f = 1 - r; 137 | int16_t ddF_x = 1; 138 | int16_t ddF_y = -2 * r; 139 | int16_t x = 0; 140 | int16_t y = r; 141 | 142 | while (x= 0) { 144 | y--; 145 | ddF_y += 2; 146 | f += ddF_y; 147 | } 148 | x++; 149 | ddF_x += 2; 150 | f += ddF_x; 151 | 152 | if (cornername & 0x1) { 153 | drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); 154 | drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); 155 | } 156 | if (cornername & 0x2) { 157 | drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); 158 | drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); 159 | } 160 | } 161 | } 162 | 163 | // Bresenham's algorithm - thx wikipedia 164 | void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, 165 | int16_t x1, int16_t y1, 166 | uint16_t color) 167 | { 168 | int16_t steep = abs(y1 - y0) > abs(x1 - x0); 169 | if (steep) { 170 | swap(x0, y0); 171 | swap(x1, y1); 172 | } 173 | 174 | if (x0 > x1) { 175 | swap(x0, x1); 176 | swap(y0, y1); 177 | } 178 | 179 | int16_t dx, dy; 180 | dx = x1 - x0; 181 | dy = abs(y1 - y0); 182 | 183 | int16_t err = dx / 2; 184 | int16_t ystep; 185 | 186 | if (y0 < y1) { 187 | ystep = 1; 188 | } else { 189 | ystep = -1; 190 | } 191 | 192 | for (; x0<=x1; x0++) { 193 | if (steep) { 194 | drawPixel(y0, x0, color); 195 | } else { 196 | drawPixel(x0, y0, color); 197 | } 198 | err -= dy; 199 | if (err < 0) { 200 | y0 += ystep; 201 | err += dx; 202 | } 203 | } 204 | } 205 | 206 | 207 | // Draw a rectangle 208 | void Adafruit_GFX::drawRect(int16_t x, int16_t y, 209 | int16_t w, int16_t h, 210 | uint16_t color) 211 | { 212 | drawFastHLine(x, y, w, color); 213 | drawFastHLine(x, y+h-1, w, color); 214 | drawFastVLine(x, y, h, color); 215 | drawFastVLine(x+w-1, y, h, color); 216 | } 217 | 218 | void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, 219 | int16_t h, uint16_t color) 220 | { 221 | // Update in subclasses if desired! 222 | drawLine(x, y, x, y+h-1, color); 223 | } 224 | 225 | 226 | void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, 227 | int16_t w, uint16_t color) 228 | { 229 | // Update in subclasses if desired! 230 | drawLine(x, y, x+w-1, y, color); 231 | } 232 | 233 | void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 234 | uint16_t color) 235 | { 236 | // Update in subclasses if desired! 237 | for (int16_t i=x; i= y1 >= y0) 291 | if (y0 > y1) { 292 | swap(y0, y1); swap(x0, x1); 293 | } 294 | if (y1 > y2) { 295 | swap(y2, y1); swap(x2, x1); 296 | } 297 | if (y0 > y1) { 298 | swap(y0, y1); swap(x0, x1); 299 | } 300 | 301 | if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing 302 | a = b = x0; 303 | if(x1 < a) a = x1; 304 | else if(x1 > b) b = x1; 305 | if(x2 < a) a = x2; 306 | else if(x2 > b) b = x2; 307 | drawFastHLine(a, y0, b-a+1, color); 308 | return; 309 | } 310 | 311 | int16_t 312 | dx01 = x1 - x0, 313 | dy01 = y1 - y0, 314 | dx02 = x2 - x0, 315 | dy02 = y2 - y0, 316 | dx12 = x2 - x1, 317 | dy12 = y2 - y1, 318 | sa = 0, 319 | sb = 0; 320 | 321 | // For upper part of triangle, find scanline crossings for segments 322 | // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 323 | // is included here (and second loop will be skipped, avoiding a /0 324 | // error there), otherwise scanline y1 is skipped here and handled 325 | // in the second loop...which also avoids a /0 error here if y0=y1 326 | // (flat-topped triangle). 327 | if(y1 == y2) last = y1; // Include y1 scanline 328 | else last = y1-1; // Skip it 329 | 330 | for(y=y0; y<=last; y++) { 331 | a = x0 + sa / dy01; 332 | b = x0 + sb / dy02; 333 | sa += dx01; 334 | sb += dx02; 335 | /* longhand: 336 | a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); 337 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 338 | */ 339 | if(a > b) swap(a,b); 340 | drawFastHLine(a, y, b-a+1, color); 341 | } 342 | 343 | // For lower part of triangle, find scanline crossings for segments 344 | // 0-2 and 1-2. This loop is skipped if y1=y2. 345 | sa = dx12 * (y - y1); 346 | sb = dx02 * (y - y0); 347 | for(; y<=y2; y++) { 348 | a = x1 + sa / dy12; 349 | b = x0 + sb / dy02; 350 | sa += dx12; 351 | sb += dx02; 352 | /* longhand: 353 | a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); 354 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 355 | */ 356 | if(a > b) swap(a,b); 357 | drawFastHLine(a, y, b-a+1, color); 358 | } 359 | } 360 | 361 | void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, 362 | const uint8_t *bitmap, int16_t w, int16_t h, 363 | uint16_t color) 364 | { 365 | int16_t i, j, byteWidth = (w + 7) / 8; 366 | 367 | for(j=0; j> (i & 7))) { 370 | drawPixel(x+i, y+j, color); 371 | } 372 | } 373 | } 374 | } 375 | 376 | 377 | #if ARDUINO >= 100 378 | size_t Adafruit_GFX::write(uint8_t c) { 379 | #else 380 | void Adafruit_GFX::write(uint8_t c) { 381 | #endif 382 | if (c == '\n') { 383 | cursor_y += textsize*8; 384 | cursor_x = 0; 385 | } else if (c == '\r') { 386 | // skip em 387 | } else { 388 | drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); 389 | cursor_x += textsize*6; 390 | if (wrap && (cursor_x > (_width - textsize*6))) { 391 | cursor_y += textsize*8; 392 | cursor_x = 0; 393 | } 394 | } 395 | #if ARDUINO >= 100 396 | return 1; 397 | #endif 398 | } 399 | 400 | // draw a character 401 | void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, 402 | uint16_t color, uint16_t bg, uint8_t size) 403 | { 404 | if((x >= _width) || // Clip right 405 | (y >= _height) || // Clip bottom 406 | ((x + 6 * size - 1) < 0) || // Clip left 407 | ((y + 8 * size - 1) < 0)) // Clip top 408 | return; 409 | 410 | for (int8_t i=0; i<6; i++ ) { 411 | uint8_t line; 412 | if (i == 5) 413 | line = 0x0; 414 | else 415 | line = pgm_read_byte(font+(c*5)+i); 416 | for (int8_t j = 0; j<8; j++) { 417 | if (line & 0x1) { 418 | if (size == 1) // default size 419 | drawPixel(x+i, y+j, color); 420 | else { // big size 421 | fillRect(x+(i*size), y+(j*size), size, size, color); 422 | } 423 | } else if (bg != color) { 424 | if (size == 1) // default size 425 | drawPixel(x+i, y+j, bg); 426 | else { // big size 427 | fillRect(x+i*size, y+j*size, size, size, bg); 428 | } 429 | } 430 | line >>= 1; 431 | } 432 | } 433 | } 434 | 435 | void Adafruit_GFX::setCursor(int16_t x, int16_t y) 436 | { 437 | cursor_x = x; 438 | cursor_y = y; 439 | } 440 | 441 | 442 | void Adafruit_GFX::setTextSize(uint8_t s) 443 | { 444 | textsize = (s > 0) ? s : 1; 445 | } 446 | 447 | 448 | void Adafruit_GFX::setTextColor(uint16_t c) { 449 | textcolor = c; 450 | textbgcolor = c; 451 | // for 'transparent' background, we'll set the bg 452 | // to the same as fg instead of using a flag 453 | } 454 | 455 | void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) 456 | { 457 | textcolor = c; 458 | textbgcolor = b; 459 | } 460 | 461 | void Adafruit_GFX::setTextWrap(boolean w) 462 | { 463 | wrap = w; 464 | } 465 | 466 | uint8_t Adafruit_GFX::getRotation(void) 467 | { 468 | return rotation; 469 | } 470 | 471 | void Adafruit_GFX::setRotation(uint8_t x) 472 | { 473 | rotation = (x & 3); 474 | switch (x) { 475 | case 0: 476 | case 2: 477 | _width = WIDTH; 478 | _height = HEIGHT; 479 | break; 480 | case 1: 481 | case 3: 482 | _width = HEIGHT; 483 | _height = WIDTH; 484 | break; 485 | } 486 | } 487 | 488 | 489 | 490 | // return the size of the display (per current rotation) 491 | int16_t Adafruit_GFX::width(void) 492 | { 493 | return _width; 494 | } 495 | 496 | int16_t Adafruit_GFX::height(void) 497 | { 498 | return _height; 499 | } 500 | 501 | void Adafruit_GFX::invertDisplay(boolean i) 502 | { 503 | // Do nothing, must be subclassed if supported 504 | } 505 | 506 | 507 | uint16_t Adafruit_GFX::newColor(uint8_t r, uint8_t g, uint8_t b) 508 | { 509 | return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); 510 | } 511 | 512 | void Adafruit_GFX::background(uint8_t red, uint8_t green, uint8_t blue) 513 | { 514 | background(newColor(red, green, blue)); 515 | } 516 | 517 | void Adafruit_GFX::background(color c) { 518 | fillScreen(c); 519 | } 520 | 521 | void Adafruit_GFX::stroke(uint8_t red, uint8_t green, uint8_t blue) 522 | { 523 | stroke(newColor(red, green, blue)); 524 | } 525 | 526 | void Adafruit_GFX::stroke(color c) 527 | { 528 | useStroke = true; 529 | strokeColor = c; 530 | setTextColor(c); 531 | } 532 | 533 | void Adafruit_GFX::noStroke() 534 | { 535 | useStroke = false; 536 | } 537 | 538 | void Adafruit_GFX::noFill() { 539 | useFill = false; 540 | } 541 | 542 | void Adafruit_GFX::fill(uint8_t red, uint8_t green, uint8_t blue) 543 | { 544 | fill(newColor(red, green, blue)); 545 | } 546 | 547 | void Adafruit_GFX::fill(color c) 548 | { 549 | useFill = true; 550 | fillColor = c; 551 | } 552 | 553 | 554 | void Adafruit_GFX::text(const char * text, int16_t x, int16_t y) 555 | { 556 | if (!useStroke) 557 | return; 558 | 559 | setTextWrap(false); 560 | setTextColor(strokeColor); 561 | setCursor(x, y); 562 | print(text); 563 | } 564 | 565 | void Adafruit_GFX::textWrap(const char * text, int16_t x, int16_t y) 566 | { 567 | if (!useStroke) 568 | return; 569 | 570 | setTextWrap(true); 571 | setTextColor(strokeColor); 572 | setCursor(x, y); 573 | print(text); 574 | } 575 | 576 | 577 | void Adafruit_GFX::textSize(uint8_t size) 578 | { 579 | setTextSize(size); 580 | } 581 | 582 | void Adafruit_GFX::point(int16_t x, int16_t y) 583 | { 584 | if (!useStroke) 585 | return; 586 | 587 | drawPixel(x, y, strokeColor); 588 | } 589 | 590 | void Adafruit_GFX::line(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 591 | { 592 | if (!useStroke) 593 | return; 594 | 595 | if (x1 == x2) { 596 | if (y1 < y2) 597 | drawFastVLine(x1, y1, y2 - y1, strokeColor); 598 | else 599 | drawFastVLine(x1, y2, y1 - y2, strokeColor); 600 | } 601 | else if (y1 == y2) { 602 | if (x1 < x2) 603 | drawFastHLine(x1, y1, x2 - x1, strokeColor); 604 | else 605 | drawFastHLine(x2, y1, x1 - x2, strokeColor); 606 | } 607 | else { 608 | drawLine(x1, y1, x2, y2, strokeColor); 609 | } 610 | } 611 | 612 | void Adafruit_GFX::rect(int16_t x, int16_t y, int16_t width, int16_t height) 613 | { 614 | if (useFill) { 615 | fillRect(x, y, width, height, fillColor); 616 | } 617 | if (useStroke) { 618 | drawRect(x, y, width, height, strokeColor); 619 | } 620 | } 621 | 622 | void Adafruit_GFX::rect(int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius) 623 | { 624 | if (radius == 0) { 625 | rect(x, y, width, height); 626 | } 627 | if (useFill) { 628 | fillRoundRect(x, y, width, height, radius, fillColor); 629 | } 630 | if (useStroke) { 631 | drawRoundRect(x, y, width, height, radius, strokeColor); 632 | } 633 | } 634 | 635 | void Adafruit_GFX::circle(int16_t x, int16_t y, int16_t r) 636 | { 637 | if (r == 0) 638 | return; 639 | 640 | if (useFill) { 641 | fillCircle(x, y, r, fillColor); 642 | } 643 | if (useStroke) { 644 | drawCircle(x, y, r, strokeColor); 645 | } 646 | } 647 | 648 | void Adafruit_GFX::triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3) 649 | { 650 | if (useFill) { 651 | fillTriangle(x1, y1, x2, y2, x3, y3, fillColor); 652 | } 653 | if (useStroke) { 654 | drawTriangle(x1, y1, x2, y2, x3, y3, strokeColor); 655 | } 656 | } 657 | 658 | #if defined(__SD_H__) // Arduino SD library 659 | 660 | #define BUFFPIXEL 20 661 | 662 | void Adafruit_GFX::image(PImage & img, uint16_t x, uint16_t y) { 663 | int w, h, row, col; 664 | uint8_t r, g, b; 665 | uint32_t pos = 0; 666 | uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel) 667 | uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer 668 | 669 | // Crop area to be loaded 670 | w = img._bmpWidth; 671 | h = img._bmpHeight; 672 | if((x+w-1) >= width()) w = width() - x; 673 | if((y+h-1) >= height()) h = height() - y; 674 | 675 | /* 676 | // Set TFT address window to clipped image bounds 677 | setAddrWindow(x, y, x+w-1, y+h-1); 678 | */ 679 | 680 | for (row=0; row= sizeof(sdbuffer)) { // Indeed 699 | img._bmpFile.read(sdbuffer, sizeof(sdbuffer)); 700 | buffidx = 0; // Set index to beginning 701 | } 702 | 703 | // Convert pixel from BMP to TFT format, push to display 704 | b = sdbuffer[buffidx++]; 705 | g = sdbuffer[buffidx++]; 706 | r = sdbuffer[buffidx++]; 707 | //pushColor(tft.Color565(r,g,b)); 708 | drawPixel(x + col, y + row, newColor(r, g, b)); 709 | 710 | } // end pixel 711 | } // end scanline 712 | 713 | } 714 | 715 | #endif 716 | -------------------------------------------------------------------------------- /src/utility/Adafruit_GFX.h: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | This is the core graphics library for all our displays, providing 3 | basic graphics primitives (points, lines, circles, etc.). It needs 4 | to be paired with a hardware-specific library for each display 5 | device we carry (handling the lower-level functions). 6 | 7 | Adafruit invests time and resources providing this open 8 | source code, please support Adafruit and open-source hardware 9 | by purchasing products from Adafruit! 10 | 11 | Written by Limor Fried/Ladyada for Adafruit Industries. 12 | Processing-like API written by Enrico Gueli for Officine Arduino. 13 | BSD license, check license.txt for more information. 14 | All text above must be included in any redistribution. 15 | ******************************************************************/ 16 | 17 | #ifndef _ADAFRUIT_GFX_H 18 | #define _ADAFRUIT_GFX_H 19 | 20 | #if ARDUINO >= 100 21 | #include "Arduino.h" 22 | #include "Print.h" 23 | #else 24 | #include "WProgram.h" 25 | #endif 26 | 27 | /* 28 | * This library can work with or without the presence of an SD 29 | * reading library (to load images). At the moment, only the 30 | * Arduino SD library is supported; it is included in 31 | * standard Arduino libraries. 32 | * 33 | * The presence of the SD library is detected by looking at the 34 | * __SD_H__ preprocessor variable, defined into 35 | * Arduino SD library to avoid double inclusion. This means 36 | * that in order to use the image-related API of Adafruit_GFX, 37 | * SD.h *must* be included before Adafruit_GFX. 38 | * 39 | * The bottom part of this include file contains the actual image 40 | * loading code; if it was in a separate .cpp file, there were no 41 | * way to check if the SD library was present or not. 42 | * 43 | * A partial solution was to include SD.h anyway, see if that works 44 | * (i.e. it is found in the include search path) and act accordingly. 45 | * But this solution relied on the preprocessor to issue only a 46 | * warning when an include file is not found. Avr-gcc, used for 47 | * Arduino 8-bit MCUs, does that, but the standard gcc-4.4, used for 48 | * Arduino Due, issues a fatal error and stops compilation. 49 | * 50 | * The best solution so far is to put the code here. It works if this 51 | * include is used only in one .cpp file in the build (this is the 52 | * case of most Arduino sketches); if used in multiple .cpp files, 53 | * the linker may complain about duplicate definitions. 54 | * 55 | */ 56 | 57 | #if defined(__SD_H__) // Arduino SD library 58 | #include "PImage.h" 59 | #else 60 | #warning "The SD library was not found. loadImage() and image() won't be supported." 61 | #endif 62 | 63 | inline void swap(int16_t &a, int16_t &b) { int16_t t = a; a = b; b = t; } 64 | 65 | /* TODO 66 | enum RectMode { 67 | CORNER, 68 | CORNERS, 69 | RADIUS, 70 | CENTER 71 | }; 72 | */ 73 | 74 | typedef uint16_t color; 75 | 76 | class Adafruit_GFX : public Print { 77 | public: 78 | 79 | Adafruit_GFX(int16_t w, int16_t h); // Constructor 80 | 81 | // This MUST be defined by the subclass 82 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 83 | 84 | 85 | 86 | // These MAY be overridden by the subclass to provide device-specific 87 | // optimized code. Otherwise 'generic' versions are used. 88 | virtual void 89 | drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 90 | uint16_t color), 91 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 92 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 93 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, 94 | uint16_t color), 95 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 96 | uint16_t color), 97 | fillScreen(uint16_t color), 98 | invertDisplay(boolean i); 99 | 100 | // These exist only with Adafruit_GFX (no subclass overrides) 101 | void 102 | drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 103 | drawCircleHelper(int16_t x0, int16_t y0, 104 | int16_t r, uint8_t cornername, uint16_t color), 105 | fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 106 | fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 107 | uint8_t cornername, int16_t delta, uint16_t color), 108 | 109 | drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 110 | int16_t x2, int16_t y2, uint16_t color), 111 | fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 112 | int16_t x2, int16_t y2, uint16_t color), 113 | drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 114 | int16_t radius, uint16_t color), 115 | fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 116 | int16_t radius, uint16_t color), 117 | 118 | drawBitmap(int16_t x, int16_t y, 119 | const uint8_t *bitmap, int16_t w, int16_t h, 120 | uint16_t color), 121 | drawChar(int16_t x, int16_t y, unsigned char c, 122 | uint16_t color, uint16_t bg, uint8_t size), 123 | setCursor(int16_t x, int16_t y), 124 | setTextColor(uint16_t c), 125 | setTextColor(uint16_t c, uint16_t bg), 126 | setTextSize(uint8_t s), 127 | setTextWrap(boolean w), 128 | setRotation(uint8_t r); 129 | 130 | #if ARDUINO >= 100 131 | virtual size_t write(uint8_t); 132 | #else 133 | virtual void write(uint8_t); 134 | #endif 135 | 136 | int16_t 137 | height(void), 138 | width(void); 139 | 140 | 141 | uint8_t getRotation(void); 142 | 143 | 144 | /* 145 | * Processing-like graphics primitives 146 | */ 147 | 148 | /// transforms a color in 16-bit form given the RGB components. 149 | /// The default implementation makes a 5-bit red, a 6-bit 150 | /// green and a 5-bit blue (MSB to LSB). Devices that use 151 | /// different scheme should override this. 152 | virtual uint16_t newColor(uint8_t red, uint8_t green, uint8_t blue); 153 | 154 | 155 | void 156 | // http://processing.org/reference/background_.html 157 | background(uint8_t red, uint8_t green, uint8_t blue), 158 | background(color c), 159 | 160 | // http://processing.org/reference/fill_.html 161 | fill(uint8_t red, uint8_t green, uint8_t blue), 162 | fill(color c), 163 | 164 | // http://processing.org/reference/noFill_.html 165 | noFill(), 166 | 167 | // http://processing.org/reference/stroke_.html 168 | stroke(uint8_t red, uint8_t green, uint8_t blue), 169 | stroke(color c), 170 | 171 | // http://processing.org/reference/noStroke_.html 172 | noStroke(), 173 | 174 | text(const char * text, int16_t x, int16_t y), 175 | textWrap(const char * text, int16_t x, int16_t y), 176 | 177 | textSize(uint8_t size), 178 | 179 | // similar to ellipse() in Processing, but with 180 | // a single radius. 181 | // http://processing.org/reference/ellipse_.html 182 | circle(int16_t x, int16_t y, int16_t r), 183 | point(int16_t x, int16_t y), 184 | line(int16_t x1, int16_t y1, int16_t x2, int16_t y2), 185 | quad(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4), 186 | rect(int16_t x, int16_t y, int16_t width, int16_t height), 187 | rect(int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius), 188 | triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3); 189 | 190 | /* TODO 191 | void rectMode(RectMode mode); 192 | 193 | void pushStyle(); 194 | void popStyle(); 195 | */ 196 | 197 | #if defined(__SD_H__) // Arduino SD library 198 | PImage loadImage(const char * fileName) { return PImage::loadImage(fileName); } 199 | 200 | void image(PImage & img, uint16_t x, uint16_t y); 201 | #endif 202 | 203 | protected: 204 | int16_t 205 | WIDTH, HEIGHT; // this is the 'raw' display w/h - never changes 206 | int16_t 207 | _width, _height, // dependent on rotation 208 | cursor_x, cursor_y; 209 | uint16_t 210 | textcolor, textbgcolor; 211 | uint8_t 212 | textsize, 213 | rotation; 214 | boolean 215 | wrap; // If set, 'wrap' text at right edge of display 216 | 217 | /* 218 | * Processing-style graphics state 219 | */ 220 | 221 | color strokeColor; 222 | bool useStroke; 223 | color fillColor; 224 | bool useFill; 225 | }; 226 | 227 | #if defined(__SD_H__) // Arduino SD library 228 | 229 | #define BUFFPIXEL 20 230 | 231 | void Adafruit_GFX::image(PImage & img, uint16_t x, uint16_t y) { 232 | int w, h, row, col; 233 | uint8_t r, g, b; 234 | uint32_t pos = 0; 235 | uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel) 236 | uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer 237 | 238 | // Crop area to be loaded 239 | w = img._bmpWidth; 240 | h = img._bmpHeight; 241 | if((x+w-1) >= width()) w = width() - x; 242 | if((y+h-1) >= height()) h = height() - y; 243 | 244 | /* 245 | // Set TFT address window to clipped image bounds 246 | setAddrWindow(x, y, x+w-1, y+h-1); 247 | */ 248 | 249 | for (row=0; row= sizeof(sdbuffer)) { // Indeed 268 | img._bmpFile.read(sdbuffer, sizeof(sdbuffer)); 269 | buffidx = 0; // Set index to beginning 270 | } 271 | 272 | // Convert pixel from BMP to TFT format, push to display 273 | b = sdbuffer[buffidx++]; 274 | g = sdbuffer[buffidx++]; 275 | r = sdbuffer[buffidx++]; 276 | //pushColor(tft.Color565(r,g,b)); 277 | drawPixel(x + col, y + row, newColor(r, g, b)); 278 | 279 | } // end pixel 280 | } // end scanline 281 | 282 | } 283 | 284 | 285 | 286 | 287 | // These read 16- and 32-bit types from the SD card file. 288 | // BMP data is stored little-endian, Arduino is little-endian too. 289 | // May need to reverse subscript order if porting elsewhere. 290 | 291 | uint16_t PImage::read16(File f) { 292 | uint16_t result; 293 | ((uint8_t *)&result)[0] = f.read(); // LSB 294 | ((uint8_t *)&result)[1] = f.read(); // MSB 295 | return result; 296 | } 297 | 298 | uint32_t PImage::read32(File f) { 299 | uint32_t result; 300 | ((uint8_t *)&result)[0] = f.read(); // LSB 301 | ((uint8_t *)&result)[1] = f.read(); 302 | ((uint8_t *)&result)[2] = f.read(); 303 | ((uint8_t *)&result)[3] = f.read(); // MSB 304 | return result; 305 | } 306 | 307 | 308 | PImage PImage::loadImage(const char * fileName) { 309 | File bmpFile; 310 | int bmpWidth, bmpHeight; // W+H in pixels 311 | uint8_t bmpDepth; // Bit depth (currently must be 24) 312 | uint32_t bmpImageoffset; // Start of image data in file 313 | uint32_t rowSize; // Not always = bmpWidth; may have padding 314 | bool flip = true; // BMP is stored bottom-to-top 315 | 316 | 317 | // Open requested file on SD card 318 | if ((bmpFile = SD.open(fileName)) == NULL) { 319 | Serial.print(F("loadImage: file not found: ")); 320 | Serial.println(fileName); 321 | return PImage(); // load error 322 | } 323 | 324 | 325 | 326 | // Parse BMP header 327 | if(read16(bmpFile) != 0x4D42) { // BMP signature 328 | Serial.println(F("loadImage: file doesn't look like a BMP")); 329 | return PImage(); 330 | } 331 | 332 | Serial.print(F("File size: ")); Serial.println(read32(bmpFile)); 333 | (void)read32(bmpFile); // Read & ignore creator bytes 334 | bmpImageoffset = read32(bmpFile); // Start of image data 335 | Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC); 336 | // Read DIB header 337 | Serial.print(F("Header size: ")); Serial.println(read32(bmpFile)); 338 | bmpWidth = read32(bmpFile); 339 | bmpHeight = read32(bmpFile); 340 | if(read16(bmpFile) != 1) { // # planes -- must be '1' 341 | Serial.println(F("loadImage: invalid n. of planes")); 342 | return PImage(); 343 | } 344 | 345 | bmpDepth = read16(bmpFile); // bits per pixel 346 | Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth); 347 | if((bmpDepth != 24) || (read32(bmpFile) != 0)) { // 0 = uncompressed { 348 | Serial.println(F("loadImage: invalid pixel format")); 349 | return PImage(); 350 | } 351 | 352 | Serial.print(F("Image size: ")); 353 | Serial.print(bmpWidth); 354 | Serial.print('x'); 355 | Serial.println(bmpHeight); 356 | 357 | // BMP rows are padded (if needed) to 4-byte boundary 358 | rowSize = (bmpWidth * 3 + 3) & ~3; 359 | 360 | // If bmpHeight is negative, image is in top-down order. 361 | // This is not canon but has been observed in the wild. 362 | if(bmpHeight < 0) { 363 | bmpHeight = -bmpHeight; 364 | flip = false; 365 | } 366 | 367 | return PImage(bmpFile, bmpWidth, bmpHeight, bmpDepth, bmpImageoffset, rowSize, flip); 368 | } 369 | 370 | #endif 371 | 372 | #endif // _ADAFRUIT_GFX_H 373 | -------------------------------------------------------------------------------- /src/utility/Adafruit_ST7735.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit 1.8" SPI display. 3 | This library works with the Adafruit 1.8" TFT Breakout w/SD card 4 | ----> http://www.adafruit.com/products/358 5 | as well as Adafruit raw 1.8" TFT display 6 | ----> http://www.adafruit.com/products/618 7 | 8 | Check out the links above for our tutorials and wiring diagrams 9 | These displays use SPI to communicate, 4 or 5 pins are required to 10 | interface (RST is optional) 11 | Adafruit invests time and resources providing this open source code, 12 | please support Adafruit and open-source hardware by purchasing 13 | products from Adafruit! 14 | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. 16 | MIT license, all text above must be included in any redistribution 17 | ****************************************************/ 18 | 19 | #include "Adafruit_ST7735.h" 20 | #include 21 | #include 22 | #include "pins_arduino.h" 23 | #include "wiring_private.h" 24 | #include 25 | 26 | inline uint16_t swapcolor(uint16_t x) { 27 | return (x << 11) | (x & 0x07E0) | (x >> 11); 28 | } 29 | 30 | 31 | // Constructor when using software SPI. All output pins are configurable. 32 | Adafruit_ST7735::Adafruit_ST7735(uint8_t cs, uint8_t rs, uint8_t sid, 33 | uint8_t sclk, uint8_t rst) : Adafruit_GFX(ST7735_TFTWIDTH, ST7735_TFTHEIGHT) 34 | { 35 | _cs = cs; 36 | _rs = rs; 37 | _sid = sid; 38 | _sclk = sclk; 39 | _rst = rst; 40 | hwSPI = false; 41 | } 42 | 43 | 44 | // Constructor when using hardware SPI. Faster, but must use SPI pins 45 | // specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.) 46 | Adafruit_ST7735::Adafruit_ST7735(uint8_t cs, uint8_t rs, uint8_t rst) : 47 | Adafruit_GFX(ST7735_TFTWIDTH, ST7735_TFTHEIGHT) 48 | { 49 | _cs = cs; 50 | _rs = rs; 51 | _rst = rst; 52 | hwSPI = true; 53 | _sid = _sclk = 0; 54 | } 55 | 56 | 57 | inline void Adafruit_ST7735::spiwrite(uint8_t c) { 58 | 59 | //Serial.println(c, HEX); 60 | 61 | if (hwSPI) { 62 | SPI.transfer(c); 63 | } else { 64 | // Fast SPI bitbang swiped from LPD8806 library 65 | for(uint8_t bit = 0x80; bit; bit >>= 1) { 66 | if(c & bit) *dataport |= datapinmask; 67 | else *dataport &= ~datapinmask; 68 | *clkport |= clkpinmask; 69 | *clkport &= ~clkpinmask; 70 | } 71 | } 72 | } 73 | 74 | 75 | void Adafruit_ST7735::writecommand(uint8_t c) { 76 | #ifdef SPI_HAS_TRANSACTION 77 | if (hwSPI) SPI.beginTransaction(spisettings); 78 | #endif 79 | 80 | #ifdef __ARDUINO_ARC__ 81 | digitalWrite(_rs, LOW); 82 | #else 83 | *rsport &= ~rspinmask; 84 | #endif 85 | *csport &= ~cspinmask; 86 | 87 | //Serial.print("C "); 88 | spiwrite(c); 89 | 90 | *csport |= cspinmask; 91 | #ifdef SPI_HAS_TRANSACTION 92 | if (hwSPI) SPI.endTransaction(); 93 | #endif 94 | } 95 | 96 | 97 | void Adafruit_ST7735::writedata(uint8_t c) { 98 | #ifdef SPI_HAS_TRANSACTION 99 | if (hwSPI) SPI.beginTransaction(spisettings); 100 | #endif 101 | 102 | #ifdef __ARDUINO_ARC__ 103 | digitalWrite(_rs, HIGH); 104 | #else 105 | *rsport |= rspinmask; 106 | #endif 107 | *csport &= ~cspinmask; 108 | 109 | //Serial.print("D "); 110 | spiwrite(c); 111 | 112 | *csport |= cspinmask; 113 | #ifdef SPI_HAS_TRANSACTION 114 | if (hwSPI) SPI.endTransaction(); 115 | #endif 116 | } 117 | 118 | 119 | // Rather than a bazillion writecommand() and writedata() calls, screen 120 | // initialization commands and arguments are organized in these tables 121 | // stored in PROGMEM. The table may look bulky, but that's mostly the 122 | // formatting -- storage-wise this is hundreds of bytes more compact 123 | // than the equivalent code. Companion function follows. 124 | #define DELAY 0x80 125 | PROGMEM const static unsigned char 126 | Bcmd[] = { // Initialization commands for 7735B screens 127 | 18, // 18 commands in list: 128 | ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay 129 | 50, // 50 ms delay 130 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay 131 | 255, // 255 = 500 ms delay 132 | ST7735_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay: 133 | 0x05, // 16-bit color 134 | 10, // 10 ms delay 135 | ST7735_FRMCTR1, 3+DELAY, // 4: Frame rate control, 3 args + delay: 136 | 0x00, // fastest refresh 137 | 0x06, // 6 lines front porch 138 | 0x03, // 3 lines back porch 139 | 10, // 10 ms delay 140 | ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg: 141 | 0x08, // Row addr/col addr, bottom to top refresh 142 | ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay: 143 | 0x15, // 1 clk cycle nonoverlap, 2 cycle gate 144 | // rise, 3 cycle osc equalize 145 | 0x02, // Fix on VTL 146 | ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg: 147 | 0x0, // Line inversion 148 | ST7735_PWCTR1 , 2+DELAY, // 8: Power control, 2 args + delay: 149 | 0x02, // GVDD = 4.7V 150 | 0x70, // 1.0uA 151 | 10, // 10 ms delay 152 | ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay: 153 | 0x05, // VGH = 14.7V, VGL = -7.35V 154 | ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay: 155 | 0x01, // Opamp current small 156 | 0x02, // Boost frequency 157 | ST7735_VMCTR1 , 2+DELAY, // 11: Power control, 2 args + delay: 158 | 0x3C, // VCOMH = 4V 159 | 0x38, // VCOML = -1.1V 160 | 10, // 10 ms delay 161 | ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay: 162 | 0x11, 0x15, 163 | ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay: 164 | 0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what 165 | 0x21, 0x1B, 0x13, 0x19, // these config values represent) 166 | 0x17, 0x15, 0x1E, 0x2B, 167 | 0x04, 0x05, 0x02, 0x0E, 168 | ST7735_GMCTRN1,16+DELAY, // 14: Sparkles and rainbows, 16 args + delay: 169 | 0x0B, 0x14, 0x08, 0x1E, // (ditto) 170 | 0x22, 0x1D, 0x18, 0x1E, 171 | 0x1B, 0x1A, 0x24, 0x2B, 172 | 0x06, 0x06, 0x02, 0x0F, 173 | 10, // 10 ms delay 174 | ST7735_CASET , 4 , // 15: Column addr set, 4 args, no delay: 175 | 0x00, 0x02, // XSTART = 2 176 | 0x00, 0x81, // XEND = 129 177 | ST7735_RASET , 4 , // 16: Row addr set, 4 args, no delay: 178 | 0x00, 0x02, // XSTART = 1 179 | 0x00, 0x81, // XEND = 160 180 | ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay 181 | 10, // 10 ms delay 182 | ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay 183 | 255 }, // 255 = 500 ms delay 184 | 185 | Rcmd1[] = { // Init for 7735R, part 1 (red or green tab) 186 | 15, // 15 commands in list: 187 | ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay 188 | 150, // 150 ms delay 189 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay 190 | 255, // 500 ms delay 191 | ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args: 192 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) 193 | ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args: 194 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) 195 | ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args: 196 | 0x01, 0x2C, 0x2D, // Dot inversion mode 197 | 0x01, 0x2C, 0x2D, // Line inversion mode 198 | ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay: 199 | 0x07, // No inversion 200 | ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay: 201 | 0xA2, 202 | 0x02, // -4.6V 203 | 0x84, // AUTO mode 204 | ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay: 205 | 0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD 206 | ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay: 207 | 0x0A, // Opamp current small 208 | 0x00, // Boost frequency 209 | ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay: 210 | 0x8A, // BCLK/2, Opamp current small & Medium low 211 | 0x2A, 212 | ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay: 213 | 0x8A, 0xEE, 214 | ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay: 215 | 0x0E, 216 | ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay 217 | ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg: 218 | 0xC8, // row addr/col addr, bottom to top refresh 219 | ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay: 220 | 0x05 }, // 16-bit color 221 | 222 | Rcmd2green[] = { // Init for 7735R, part 2 (green tab only) 223 | 2, // 2 commands in list: 224 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay: 225 | 0x00, 0x02, // XSTART = 0 226 | 0x00, 0x7F+0x02, // XEND = 127 227 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay: 228 | 0x00, 0x01, // XSTART = 0 229 | 0x00, 0x9F+0x01 }, // XEND = 159 230 | Rcmd2red[] = { // Init for 7735R, part 2 (red tab only) 231 | 2, // 2 commands in list: 232 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay: 233 | 0x00, 0x00, // XSTART = 0 234 | 0x00, 0x7F, // XEND = 127 235 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay: 236 | 0x00, 0x00, // XSTART = 0 237 | 0x00, 0x9F }, // XEND = 159 238 | 239 | Rcmd3[] = { // Init for 7735R, part 3 (red or green tab) 240 | 4, // 4 commands in list: 241 | ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay: 242 | 0x02, 0x1c, 0x07, 0x12, 243 | 0x37, 0x32, 0x29, 0x2d, 244 | 0x29, 0x25, 0x2B, 0x39, 245 | 0x00, 0x01, 0x03, 0x10, 246 | ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay: 247 | 0x03, 0x1d, 0x07, 0x06, 248 | 0x2E, 0x2C, 0x29, 0x2D, 249 | 0x2E, 0x2E, 0x37, 0x3F, 250 | 0x00, 0x00, 0x02, 0x10, 251 | ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay 252 | 10, // 10 ms delay 253 | ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay 254 | 100 }, // 100 ms delay 255 | Gcmd[] = { // Initialization commands for 7735B screens 256 | 19, // 18 commands in list: 257 | ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay 258 | 50, // 50 ms delay 259 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay 260 | 100, // 255 = 500 ms delay 261 | 0x26 , 1, // 3: Set default gamma 262 | 0x04, // 16-bit color 263 | 0xb1, 2, // 4: Frame Rate 264 | 0x0b, 265 | 0x14, 266 | 0xc0, 2, // 5: VRH1[4:0] & VC[2:0] 267 | 0x08, 268 | 0x00, 269 | 0xc1, 1, // 6: BT[2:0] 270 | 0x05, 271 | 0xc5, 2, // 7: VMH[6:0] & VML[6:0] 272 | 0x41, 273 | 0x30, 274 | 0xc7, 1, // 8: LCD Driving control 275 | 0xc1, 276 | 0xEC, 1, // 9: Set pumping color freq 277 | 0x1b, 278 | 0x3a , 1 + DELAY, // 10: Set color format 279 | 0x55, // 16-bit color 280 | 100, 281 | 0x2a, 4, // 11: Set Column Address 282 | 0x00, 283 | 0x00, 284 | 0x00, 285 | 0x7f, 286 | 0x2b, 4, // 12: Set Page Address 287 | 0x00, 288 | 0x00, 289 | 0x00, 290 | 0x9f, 291 | 0x36, 1, // 12+1: Set Scanning Direction 292 | 0xc8, 293 | 0xb7, 1, // 14: Set Source Output Direciton 294 | 0x00, 295 | 0xf2, 1, // 15: Enable Gamma bit 296 | 0x00, 297 | 0xe0, 15 + DELAY, // 16: magic 298 | 0x28, 0x24, 0x22, 0x31, 299 | 0x2b, 0x0e, 0x53, 0xa5, 300 | 0x42, 0x16, 0x18, 0x12, 301 | 0x1a, 0x14, 0x03, 302 | 50, 303 | 0xe1, 15 + DELAY, // 17: more magic 304 | 0x17, 0x1b, 0x1d, 0x0e, 305 | 0x14, 0x11, 0x2c, 0xa5, 306 | 0x3d, 0x09, 0x27, 0x2d, 307 | 0x25, 0x2b, 0x3c, 308 | 50, 309 | ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay 310 | 10, // 10 ms delay 311 | ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay 312 | 255 }; // 255 = 500 ms delay 313 | 314 | 315 | 316 | // Companion code to the above tables. Reads and issues 317 | // a series of LCD commands stored in PROGMEM byte array. 318 | void Adafruit_ST7735::commandList(const uint8_t *addr) { 319 | 320 | uint8_t numCommands, numArgs; 321 | uint16_t ms; 322 | 323 | numCommands = pgm_read_byte(addr++); // Number of commands to follow 324 | while(numCommands--) { // For each command... 325 | writecommand(pgm_read_byte(addr++)); // Read, issue command 326 | numArgs = pgm_read_byte(addr++); // Number of args to follow 327 | ms = numArgs & DELAY; // If hibit set, delay follows args 328 | numArgs &= ~DELAY; // Mask out delay bit 329 | while(numArgs--) { // For each argument... 330 | writedata(pgm_read_byte(addr++)); // Read, issue argument 331 | } 332 | 333 | if(ms) { 334 | ms = pgm_read_byte(addr++); // Read post-command delay time (ms) 335 | if(ms == 255) ms = 500; // If 255, delay for 500 ms 336 | delay(ms); 337 | } 338 | } 339 | } 340 | 341 | 342 | // Initialization code common to both 'B' and 'R' type displays 343 | void Adafruit_ST7735::commonInit(const uint8_t *cmdList) { 344 | 345 | colstart = rowstart = 0; // May be overridden in init func 346 | 347 | pinMode(_rs, OUTPUT); 348 | pinMode(_cs, OUTPUT); 349 | csport = portOutputRegister(digitalPinToPort(_cs)); 350 | cspinmask = digitalPinToBitMask(_cs); 351 | rsport = portOutputRegister(digitalPinToPort(_rs)); 352 | rspinmask = digitalPinToBitMask(_rs); 353 | 354 | if(hwSPI) { // Using hardware SPI 355 | SPI.begin(); 356 | #ifdef SPI_HAS_TRANSACTION 357 | spisettings = SPISettings(4000000L, MSBFIRST, SPI_MODE0); 358 | #else 359 | #if defined(ARDUINO_ARCH_SAM) 360 | SPI.setClockDivider(24); // 4 MHz (half speed) 361 | #else 362 | SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz (half speed) 363 | #endif 364 | SPI.setBitOrder(MSBFIRST); 365 | SPI.setDataMode(SPI_MODE0); 366 | #endif // SPI_HAS_TRANSACTION 367 | } else { 368 | pinMode(_sclk, OUTPUT); 369 | pinMode(_sid , OUTPUT); 370 | clkport = portOutputRegister(digitalPinToPort(_sclk)); 371 | clkpinmask = digitalPinToBitMask(_sclk); 372 | dataport = portOutputRegister(digitalPinToPort(_sid)); 373 | datapinmask = digitalPinToBitMask(_sid); 374 | *clkport &= ~clkpinmask; 375 | *dataport &= ~datapinmask; 376 | } 377 | 378 | // toggle RST low to reset; CS low so it'll listen to us 379 | *csport &= ~cspinmask; 380 | if (_rst) { 381 | pinMode(_rst, OUTPUT); 382 | digitalWrite(_rst, HIGH); 383 | delay(500); 384 | digitalWrite(_rst, LOW); 385 | delay(500); 386 | digitalWrite(_rst, HIGH); 387 | delay(500); 388 | } 389 | 390 | if(cmdList) commandList(cmdList); 391 | } 392 | 393 | 394 | // Initialization for ST7735B screens 395 | void Adafruit_ST7735::initB(void) { 396 | commonInit(Bcmd); 397 | } 398 | 399 | 400 | // Initialization for ST7735B screens 401 | void Adafruit_ST7735::initG(void) { 402 | commonInit(Gcmd); 403 | } 404 | 405 | 406 | // Initialization for ST7735R screens (green or red tabs) 407 | void Adafruit_ST7735::initR(uint8_t options) { 408 | commonInit(Rcmd1); 409 | if(options == INITR_GREENTAB) { 410 | commandList(Rcmd2green); 411 | colstart = 2; 412 | rowstart = 1; 413 | } else { 414 | // colstart, rowstart left at default '0' values 415 | commandList(Rcmd2red); 416 | } 417 | commandList(Rcmd3); 418 | tabcolor = options; 419 | } 420 | 421 | 422 | void Adafruit_ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, 423 | uint8_t y1) { 424 | 425 | writecommand(ST7735_CASET); // Column addr set 426 | writedata(0x00); 427 | writedata(x0+colstart); // XSTART 428 | writedata(0x00); 429 | writedata(x1+colstart); // XEND 430 | 431 | writecommand(ST7735_RASET); // Row addr set 432 | writedata(0x00); 433 | writedata(y0+rowstart); // YSTART 434 | writedata(0x00); 435 | writedata(y1+rowstart); // YEND 436 | 437 | writecommand(ST7735_RAMWR); // write to RAM 438 | } 439 | 440 | 441 | void Adafruit_ST7735::pushColor(uint16_t color) { 442 | #ifdef SPI_HAS_TRANSACTION 443 | if (hwSPI) SPI.beginTransaction(spisettings); 444 | #endif 445 | 446 | #ifdef __ARDUINO_ARC__ 447 | digitalWrite(_rs, HIGH); 448 | #else 449 | *rsport |= rspinmask; 450 | #endif 451 | *csport &= ~cspinmask; 452 | 453 | if (tabcolor == INITR_BLACKTAB) color = swapcolor(color); 454 | spiwrite(color >> 8); 455 | spiwrite(color); 456 | 457 | *csport |= cspinmask; 458 | #ifdef SPI_HAS_TRANSACTION 459 | if (hwSPI) SPI.endTransaction(); 460 | #endif 461 | } 462 | 463 | void Adafruit_ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) { 464 | 465 | if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; 466 | 467 | setAddrWindow(x,y,x+1,y+1); 468 | 469 | #ifdef SPI_HAS_TRANSACTION 470 | if (hwSPI) SPI.beginTransaction(spisettings); 471 | #endif 472 | 473 | #ifdef __ARDUINO_ARC__ 474 | digitalWrite(_rs, HIGH); 475 | #else 476 | *rsport |= rspinmask; 477 | #endif 478 | *csport &= ~cspinmask; 479 | 480 | if (tabcolor == INITR_BLACKTAB) color = swapcolor(color); 481 | 482 | spiwrite(color >> 8); 483 | spiwrite(color); 484 | 485 | *csport |= cspinmask; 486 | #ifdef SPI_HAS_TRANSACTION 487 | if (hwSPI) SPI.endTransaction(); 488 | #endif 489 | } 490 | 491 | 492 | void Adafruit_ST7735::drawFastVLine(int16_t x, int16_t y, int16_t h, 493 | uint16_t color) { 494 | 495 | // Rudimentary clipping 496 | if((x >= _width) || (y >= _height)) return; 497 | if((y+h-1) >= _height) h = _height-y; 498 | setAddrWindow(x, y, x, y+h-1); 499 | 500 | if (tabcolor == INITR_BLACKTAB) color = swapcolor(color); 501 | 502 | uint8_t hi = color >> 8, lo = color; 503 | #ifdef SPI_HAS_TRANSACTION 504 | if (hwSPI) SPI.beginTransaction(spisettings); 505 | #endif 506 | 507 | #ifdef __ARDUINO_ARC__ 508 | digitalWrite(_rs, HIGH); 509 | #else 510 | *rsport |= rspinmask; 511 | #endif 512 | *csport &= ~cspinmask; 513 | while (h--) { 514 | spiwrite(hi); 515 | spiwrite(lo); 516 | } 517 | *csport |= cspinmask; 518 | #ifdef SPI_HAS_TRANSACTION 519 | if (hwSPI) SPI.endTransaction(); 520 | #endif 521 | } 522 | 523 | 524 | void Adafruit_ST7735::drawFastHLine(int16_t x, int16_t y, int16_t w, 525 | uint16_t color) { 526 | 527 | // Rudimentary clipping 528 | if((x >= _width) || (y >= _height)) return; 529 | if((x+w-1) >= _width) w = _width-x; 530 | setAddrWindow(x, y, x+w-1, y); 531 | 532 | if (tabcolor == INITR_BLACKTAB) color = swapcolor(color); 533 | 534 | uint8_t hi = color >> 8, lo = color; 535 | #ifdef SPI_HAS_TRANSACTION 536 | if (hwSPI) SPI.beginTransaction(spisettings); 537 | #endif 538 | 539 | #ifdef __ARDUINO_ARC__ 540 | digitalWrite(_rs, HIGH); 541 | #else 542 | *rsport |= rspinmask; 543 | #endif 544 | *csport &= ~cspinmask; 545 | while (w--) { 546 | spiwrite(hi); 547 | spiwrite(lo); 548 | } 549 | *csport |= cspinmask; 550 | #ifdef SPI_HAS_TRANSACTION 551 | if (hwSPI) SPI.endTransaction(); 552 | #endif 553 | } 554 | 555 | 556 | 557 | void Adafruit_ST7735::fillScreen(uint16_t color) { 558 | fillRect(0, 0, _width, _height, color); 559 | } 560 | 561 | 562 | 563 | // fill a rectangle 564 | void Adafruit_ST7735::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 565 | uint16_t color) { 566 | 567 | // rudimentary clipping (drawChar w/big text requires this) 568 | if((x >= _width) || (y >= _height)) return; 569 | if((x + w - 1) >= _width) w = _width - x; 570 | if((y + h - 1) >= _height) h = _height - y; 571 | 572 | if (tabcolor == INITR_BLACKTAB) color = swapcolor(color); 573 | 574 | setAddrWindow(x, y, x+w-1, y+h-1); 575 | 576 | uint8_t hi = color >> 8, lo = color; 577 | #ifdef SPI_HAS_TRANSACTION 578 | if (hwSPI) SPI.beginTransaction(spisettings); 579 | #endif 580 | 581 | #ifdef __ARDUINO_ARC__ 582 | digitalWrite(_rs, HIGH); 583 | #else 584 | *rsport |= rspinmask; 585 | #endif 586 | *csport &= ~cspinmask; 587 | for(y=h; y>0; y--) { 588 | for(x=w; x>0; x--) { 589 | spiwrite(hi); 590 | spiwrite(lo); 591 | } 592 | } 593 | 594 | *csport |= cspinmask; 595 | #ifdef SPI_HAS_TRANSACTION 596 | if (hwSPI) SPI.endTransaction(); 597 | #endif 598 | } 599 | 600 | 601 | #define MADCTL_MY 0x80 602 | #define MADCTL_MX 0x40 603 | #define MADCTL_MV 0x20 604 | #define MADCTL_ML 0x10 605 | #define MADCTL_RGB 0x08 606 | #define MADCTL_MH 0x04 607 | 608 | void Adafruit_ST7735::setRotation(uint8_t m) { 609 | 610 | writecommand(ST7735_MADCTL); 611 | rotation = m % 4; // can't be higher than 3 612 | switch (rotation) { 613 | case 0: 614 | writedata(MADCTL_MX | MADCTL_MY | MADCTL_RGB); 615 | _width = ST7735_TFTWIDTH; 616 | _height = ST7735_TFTHEIGHT; 617 | break; 618 | case 1: 619 | writedata(MADCTL_MY | MADCTL_MV | MADCTL_RGB); 620 | _width = ST7735_TFTHEIGHT; 621 | _height = ST7735_TFTWIDTH; 622 | break; 623 | case 2: 624 | writedata(MADCTL_RGB); 625 | _width = ST7735_TFTWIDTH; 626 | _height = ST7735_TFTHEIGHT; 627 | break; 628 | case 3: 629 | writedata(MADCTL_MX | MADCTL_MV | MADCTL_RGB); 630 | _width = ST7735_TFTHEIGHT; 631 | _height = ST7735_TFTWIDTH; 632 | break; 633 | } 634 | } 635 | 636 | 637 | void Adafruit_ST7735::invertDisplay(boolean i) { 638 | writecommand(i ? ST7735_INVON : ST7735_INVOFF); 639 | } 640 | 641 | 642 | ////////// stuff not actively being used, but kept for posterity 643 | /* 644 | 645 | uint8_t Adafruit_ST7735::spiread(void) { 646 | uint8_t r = 0; 647 | if (_sid > 0) { 648 | r = shiftIn(_sid, _sclk, MSBFIRST); 649 | } else { 650 | //SID_DDR &= ~_BV(SID); 651 | //int8_t i; 652 | //for (i=7; i>=0; i--) { 653 | // SCLK_PORT &= ~_BV(SCLK); 654 | // r <<= 1; 655 | // r |= (SID_PIN >> SID) & 0x1; 656 | // SCLK_PORT |= _BV(SCLK); 657 | //} 658 | //SID_DDR |= _BV(SID); 659 | 660 | } 661 | return r; 662 | } 663 | 664 | 665 | void Adafruit_ST7735::dummyclock(void) { 666 | 667 | if (_sid > 0) { 668 | digitalWrite(_sclk, LOW); 669 | digitalWrite(_sclk, HIGH); 670 | } else { 671 | // SCLK_PORT &= ~_BV(SCLK); 672 | //SCLK_PORT |= _BV(SCLK); 673 | } 674 | } 675 | uint8_t Adafruit_ST7735::readdata(void) { 676 | *portOutputRegister(rsport) |= rspin; 677 | 678 | *portOutputRegister(csport) &= ~ cspin; 679 | 680 | uint8_t r = spiread(); 681 | 682 | *portOutputRegister(csport) |= cspin; 683 | 684 | return r; 685 | 686 | } 687 | 688 | uint8_t Adafruit_ST7735::readcommand8(uint8_t c) { 689 | digitalWrite(_rs, LOW); 690 | 691 | *portOutputRegister(csport) &= ~ cspin; 692 | 693 | spiwrite(c); 694 | 695 | digitalWrite(_rs, HIGH); 696 | pinMode(_sid, INPUT); // input! 697 | digitalWrite(_sid, LOW); // low 698 | spiread(); 699 | uint8_t r = spiread(); 700 | 701 | 702 | *portOutputRegister(csport) |= cspin; 703 | 704 | 705 | pinMode(_sid, OUTPUT); // back to output 706 | return r; 707 | } 708 | 709 | 710 | uint16_t Adafruit_ST7735::readcommand16(uint8_t c) { 711 | digitalWrite(_rs, LOW); 712 | if (_cs) 713 | digitalWrite(_cs, LOW); 714 | 715 | spiwrite(c); 716 | pinMode(_sid, INPUT); // input! 717 | uint16_t r = spiread(); 718 | r <<= 8; 719 | r |= spiread(); 720 | if (_cs) 721 | digitalWrite(_cs, HIGH); 722 | 723 | pinMode(_sid, OUTPUT); // back to output 724 | return r; 725 | } 726 | 727 | uint32_t Adafruit_ST7735::readcommand32(uint8_t c) { 728 | digitalWrite(_rs, LOW); 729 | if (_cs) 730 | digitalWrite(_cs, LOW); 731 | spiwrite(c); 732 | pinMode(_sid, INPUT); // input! 733 | 734 | dummyclock(); 735 | dummyclock(); 736 | 737 | uint32_t r = spiread(); 738 | r <<= 8; 739 | r |= spiread(); 740 | r <<= 8; 741 | r |= spiread(); 742 | r <<= 8; 743 | r |= spiread(); 744 | if (_cs) 745 | digitalWrite(_cs, HIGH); 746 | 747 | pinMode(_sid, OUTPUT); // back to output 748 | return r; 749 | } 750 | 751 | */ 752 | -------------------------------------------------------------------------------- /src/utility/Adafruit_ST7735.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit 1.8" SPI display. 3 | This library works with the Adafruit 1.8" TFT Breakout w/SD card 4 | ----> http://www.adafruit.com/products/358 5 | as well as Adafruit raw 1.8" TFT display 6 | ----> http://www.adafruit.com/products/618 7 | 8 | Check out the links above for our tutorials and wiring diagrams 9 | These displays use SPI to communicate, 4 or 5 pins are required to 10 | interface (RST is optional) 11 | Adafruit invests time and resources providing this open source code, 12 | please support Adafruit and open-source hardware by purchasing 13 | products from Adafruit! 14 | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. 16 | MIT license, all text above must be included in any redistribution 17 | ****************************************************/ 18 | 19 | #ifndef _ADAFRUIT_ST7735H_ 20 | #define _ADAFRUIT_ST7735H_ 21 | 22 | #if ARDUINO >= 100 23 | #include "Arduino.h" 24 | #include "Print.h" 25 | #else 26 | #include "WProgram.h" 27 | #endif 28 | #include "Adafruit_GFX.h" 29 | #include 30 | #include 31 | 32 | // some flags for initR() :( 33 | #define INITR_GREENTAB 0x0 34 | #define INITR_REDTAB 0x1 35 | #define INITR_BLACKTAB 0x2 36 | 37 | #define ST7735_TFTWIDTH 128 38 | #define ST7735_TFTHEIGHT 160 39 | 40 | #define ST7735_NOP 0x00 41 | #define ST7735_SWRESET 0x01 42 | #define ST7735_RDDID 0x04 43 | #define ST7735_RDDST 0x09 44 | 45 | #define ST7735_SLPIN 0x10 46 | #define ST7735_SLPOUT 0x11 47 | #define ST7735_PTLON 0x12 48 | #define ST7735_NORON 0x13 49 | 50 | #define ST7735_INVOFF 0x20 51 | #define ST7735_INVON 0x21 52 | #define ST7735_DISPOFF 0x28 53 | #define ST7735_DISPON 0x29 54 | #define ST7735_CASET 0x2A 55 | #define ST7735_RASET 0x2B 56 | #define ST7735_RAMWR 0x2C 57 | #define ST7735_RAMRD 0x2E 58 | 59 | #define ST7735_PTLAR 0x30 60 | #define ST7735_COLMOD 0x3A 61 | #define ST7735_MADCTL 0x36 62 | 63 | #define ST7735_FRMCTR1 0xB1 64 | #define ST7735_FRMCTR2 0xB2 65 | #define ST7735_FRMCTR3 0xB3 66 | #define ST7735_INVCTR 0xB4 67 | #define ST7735_DISSET5 0xB6 68 | 69 | #define ST7735_PWCTR1 0xC0 70 | #define ST7735_PWCTR2 0xC1 71 | #define ST7735_PWCTR3 0xC2 72 | #define ST7735_PWCTR4 0xC3 73 | #define ST7735_PWCTR5 0xC4 74 | #define ST7735_VMCTR1 0xC5 75 | 76 | #define ST7735_RDID1 0xDA 77 | #define ST7735_RDID2 0xDB 78 | #define ST7735_RDID3 0xDC 79 | #define ST7735_RDID4 0xDD 80 | 81 | #define ST7735_PWCTR6 0xFC 82 | 83 | #define ST7735_GMCTRP1 0xE0 84 | #define ST7735_GMCTRN1 0xE1 85 | 86 | // Color definitions 87 | #define ST7735_BLACK 0x0000 88 | #define ST7735_BLUE 0x001F 89 | #define ST7735_RED 0xF800 90 | #define ST7735_GREEN 0x07E0 91 | #define ST7735_CYAN 0x07FF 92 | #define ST7735_MAGENTA 0xF81F 93 | #define ST7735_YELLOW 0xFFE0 94 | #define ST7735_WHITE 0xFFFF 95 | 96 | 97 | class Adafruit_ST7735 : public Adafruit_GFX { 98 | 99 | public: 100 | 101 | Adafruit_ST7735(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK, 102 | uint8_t RST); 103 | Adafruit_ST7735(uint8_t CS, uint8_t RS, uint8_t RST); 104 | 105 | void initB(void), // for ST7735B displays 106 | initG(void), // for ILI9163C displays 107 | initR(uint8_t options = INITR_GREENTAB), // for ST7735R 108 | setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1), 109 | pushColor(uint16_t color), 110 | fillScreen(uint16_t color), 111 | drawPixel(int16_t x, int16_t y, uint16_t color), 112 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 113 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 114 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 115 | uint16_t color), 116 | setRotation(uint8_t r), 117 | invertDisplay(boolean i); 118 | uint16_t Color565(uint8_t r, uint8_t g, uint8_t b) { return newColor(r, g, b);} 119 | 120 | /* These are not for current use, 8-bit protocol only! 121 | uint8_t readdata(void), 122 | readcommand8(uint8_t); 123 | uint16_t readcommand16(uint8_t); 124 | uint32_t readcommand32(uint8_t); 125 | void dummyclock(void); 126 | */ 127 | 128 | private: 129 | uint8_t tabcolor; 130 | 131 | void spiwrite(uint8_t), 132 | writecommand(uint8_t c), 133 | writedata(uint8_t d), 134 | commandList(const uint8_t *addr), 135 | commonInit(const uint8_t *cmdList); 136 | //uint8_t spiread(void); 137 | 138 | boolean hwSPI; 139 | #ifdef SPI_HAS_TRANSACTION 140 | SPISettings spisettings; 141 | #endif 142 | #if defined(ARDUINO_ARCH_SAM) || defined(__ARDUINO_ARC__) || \ 143 | defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_SAMD) 144 | volatile uint32_t *dataport, *clkport, *csport, *rsport; 145 | uint32_t _cs, _rs, _rst, _sid, _sclk, 146 | datapinmask, clkpinmask, cspinmask, rspinmask, 147 | colstart, rowstart; // some displays need this changed 148 | #else 149 | volatile uint8_t *dataport, *clkport, *csport, *rsport; 150 | uint8_t _cs, _rs, _rst, _sid, _sclk, 151 | datapinmask, clkpinmask, cspinmask, rspinmask, 152 | colstart, rowstart; // some displays need this changed 153 | #endif 154 | }; 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /src/utility/PImage.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _PIMAGE_H 4 | #define _PIMAGE_H 5 | 6 | class Adafruit_GFX; 7 | 8 | #if defined(__SD_H__) // Arduino SD library 9 | 10 | 11 | /// This class mimics Processing's PImage, but with fewer 12 | /// capabilities. It allows an image stored in the SD card to be 13 | /// drawn to the display. 14 | /// @author Enrico Gueli 15 | class PImage { 16 | public: 17 | PImage() : 18 | _valid(false), 19 | _bmpWidth(0), 20 | _bmpHeight(0) { } 21 | 22 | void draw(Adafruit_GFX & glcd, int16_t x, int16_t y); 23 | 24 | static PImage loadImage(const char * fileName); 25 | 26 | void close() { _bmpFile.close(); } 27 | 28 | bool isValid() { return _valid; } 29 | 30 | int width() { return _bmpWidth; } 31 | int height() { return _bmpHeight; } 32 | 33 | private: 34 | friend class Adafruit_GFX; 35 | 36 | File _bmpFile; 37 | int _bmpWidth, _bmpHeight; // W+H in pixels 38 | uint8_t _bmpDepth; // Bit depth (currently must be 24) 39 | uint32_t _bmpImageoffset; // Start of image data in file 40 | uint32_t _rowSize; // Not always = bmpWidth; may have padding 41 | bool _flip; 42 | 43 | bool _valid; 44 | 45 | PImage(File & bmpFile, int bmpWidth, int bmpHeight, uint8_t bmpDepth, uint32_t bmpImageoffset, uint32_t rowSize, bool flip) : 46 | _bmpFile(bmpFile), 47 | _bmpWidth(bmpWidth), 48 | _bmpHeight(bmpHeight), 49 | _bmpDepth(bmpDepth), 50 | _bmpImageoffset(bmpImageoffset), 51 | _rowSize(rowSize), 52 | _flip(flip), 53 | _valid(true) // since Adafruit_GFX is friend, we could just let it write the variables and save some CPU cycles 54 | { } 55 | 56 | static uint16_t read16(File f); 57 | static uint32_t read32(File f); 58 | 59 | // TODO close the file in ~PImage and PImage(const PImage&) 60 | 61 | }; 62 | 63 | #endif 64 | 65 | #endif // _PIMAGE_H 66 | -------------------------------------------------------------------------------- /src/utility/glcdfont.c: -------------------------------------------------------------------------------- 1 | #if !defined(ARDUINO_ARCH_SAM) && !defined(__ARDUINO_ARC__) && \ 2 | !defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_SAMD) 3 | #include 4 | #endif 5 | #include 6 | 7 | #ifndef FONT5X7_H 8 | #define FONT5X7_H 9 | 10 | // standard ascii 5x7 font 11 | 12 | static const unsigned char font[] PROGMEM = { 13 | 0x00, 0x00, 0x00, 0x00, 0x00, 14 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 15 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 16 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 17 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 18 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 19 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 20 | 0x00, 0x18, 0x3C, 0x18, 0x00, 21 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 22 | 0x00, 0x18, 0x24, 0x18, 0x00, 23 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 24 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 25 | 0x26, 0x29, 0x79, 0x29, 0x26, 26 | 0x40, 0x7F, 0x05, 0x05, 0x07, 27 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 28 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 29 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 30 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 31 | 0x14, 0x22, 0x7F, 0x22, 0x14, 32 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 33 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 34 | 0x00, 0x66, 0x89, 0x95, 0x6A, 35 | 0x60, 0x60, 0x60, 0x60, 0x60, 36 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 37 | 0x08, 0x04, 0x7E, 0x04, 0x08, 38 | 0x10, 0x20, 0x7E, 0x20, 0x10, 39 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 40 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 41 | 0x1E, 0x10, 0x10, 0x10, 0x10, 42 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 43 | 0x30, 0x38, 0x3E, 0x38, 0x30, 44 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x5F, 0x00, 0x00, 47 | 0x00, 0x07, 0x00, 0x07, 0x00, 48 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 49 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 50 | 0x23, 0x13, 0x08, 0x64, 0x62, 51 | 0x36, 0x49, 0x56, 0x20, 0x50, 52 | 0x00, 0x08, 0x07, 0x03, 0x00, 53 | 0x00, 0x1C, 0x22, 0x41, 0x00, 54 | 0x00, 0x41, 0x22, 0x1C, 0x00, 55 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 56 | 0x08, 0x08, 0x3E, 0x08, 0x08, 57 | 0x00, 0x80, 0x70, 0x30, 0x00, 58 | 0x08, 0x08, 0x08, 0x08, 0x08, 59 | 0x00, 0x00, 0x60, 0x60, 0x00, 60 | 0x20, 0x10, 0x08, 0x04, 0x02, 61 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 62 | 0x00, 0x42, 0x7F, 0x40, 0x00, 63 | 0x72, 0x49, 0x49, 0x49, 0x46, 64 | 0x21, 0x41, 0x49, 0x4D, 0x33, 65 | 0x18, 0x14, 0x12, 0x7F, 0x10, 66 | 0x27, 0x45, 0x45, 0x45, 0x39, 67 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 68 | 0x41, 0x21, 0x11, 0x09, 0x07, 69 | 0x36, 0x49, 0x49, 0x49, 0x36, 70 | 0x46, 0x49, 0x49, 0x29, 0x1E, 71 | 0x00, 0x00, 0x14, 0x00, 0x00, 72 | 0x00, 0x40, 0x34, 0x00, 0x00, 73 | 0x00, 0x08, 0x14, 0x22, 0x41, 74 | 0x14, 0x14, 0x14, 0x14, 0x14, 75 | 0x00, 0x41, 0x22, 0x14, 0x08, 76 | 0x02, 0x01, 0x59, 0x09, 0x06, 77 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 78 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 79 | 0x7F, 0x49, 0x49, 0x49, 0x36, 80 | 0x3E, 0x41, 0x41, 0x41, 0x22, 81 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 82 | 0x7F, 0x49, 0x49, 0x49, 0x41, 83 | 0x7F, 0x09, 0x09, 0x09, 0x01, 84 | 0x3E, 0x41, 0x41, 0x51, 0x73, 85 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 86 | 0x00, 0x41, 0x7F, 0x41, 0x00, 87 | 0x20, 0x40, 0x41, 0x3F, 0x01, 88 | 0x7F, 0x08, 0x14, 0x22, 0x41, 89 | 0x7F, 0x40, 0x40, 0x40, 0x40, 90 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 91 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 92 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 93 | 0x7F, 0x09, 0x09, 0x09, 0x06, 94 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 95 | 0x7F, 0x09, 0x19, 0x29, 0x46, 96 | 0x26, 0x49, 0x49, 0x49, 0x32, 97 | 0x03, 0x01, 0x7F, 0x01, 0x03, 98 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 99 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 100 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 101 | 0x63, 0x14, 0x08, 0x14, 0x63, 102 | 0x03, 0x04, 0x78, 0x04, 0x03, 103 | 0x61, 0x59, 0x49, 0x4D, 0x43, 104 | 0x00, 0x7F, 0x41, 0x41, 0x41, 105 | 0x02, 0x04, 0x08, 0x10, 0x20, 106 | 0x00, 0x41, 0x41, 0x41, 0x7F, 107 | 0x04, 0x02, 0x01, 0x02, 0x04, 108 | 0x40, 0x40, 0x40, 0x40, 0x40, 109 | 0x00, 0x03, 0x07, 0x08, 0x00, 110 | 0x20, 0x54, 0x54, 0x78, 0x40, 111 | 0x7F, 0x28, 0x44, 0x44, 0x38, 112 | 0x38, 0x44, 0x44, 0x44, 0x28, 113 | 0x38, 0x44, 0x44, 0x28, 0x7F, 114 | 0x38, 0x54, 0x54, 0x54, 0x18, 115 | 0x00, 0x08, 0x7E, 0x09, 0x02, 116 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 117 | 0x7F, 0x08, 0x04, 0x04, 0x78, 118 | 0x00, 0x44, 0x7D, 0x40, 0x00, 119 | 0x20, 0x40, 0x40, 0x3D, 0x00, 120 | 0x7F, 0x10, 0x28, 0x44, 0x00, 121 | 0x00, 0x41, 0x7F, 0x40, 0x00, 122 | 0x7C, 0x04, 0x78, 0x04, 0x78, 123 | 0x7C, 0x08, 0x04, 0x04, 0x78, 124 | 0x38, 0x44, 0x44, 0x44, 0x38, 125 | 0xFC, 0x18, 0x24, 0x24, 0x18, 126 | 0x18, 0x24, 0x24, 0x18, 0xFC, 127 | 0x7C, 0x08, 0x04, 0x04, 0x08, 128 | 0x48, 0x54, 0x54, 0x54, 0x24, 129 | 0x04, 0x04, 0x3F, 0x44, 0x24, 130 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 131 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 132 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 133 | 0x44, 0x28, 0x10, 0x28, 0x44, 134 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 135 | 0x44, 0x64, 0x54, 0x4C, 0x44, 136 | 0x00, 0x08, 0x36, 0x41, 0x00, 137 | 0x00, 0x00, 0x77, 0x00, 0x00, 138 | 0x00, 0x41, 0x36, 0x08, 0x00, 139 | 0x02, 0x01, 0x02, 0x04, 0x02, 140 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 141 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 142 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 143 | 0x38, 0x54, 0x54, 0x55, 0x59, 144 | 0x21, 0x55, 0x55, 0x79, 0x41, 145 | 0x21, 0x54, 0x54, 0x78, 0x41, 146 | 0x21, 0x55, 0x54, 0x78, 0x40, 147 | 0x20, 0x54, 0x55, 0x79, 0x40, 148 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 149 | 0x39, 0x55, 0x55, 0x55, 0x59, 150 | 0x39, 0x54, 0x54, 0x54, 0x59, 151 | 0x39, 0x55, 0x54, 0x54, 0x58, 152 | 0x00, 0x00, 0x45, 0x7C, 0x41, 153 | 0x00, 0x02, 0x45, 0x7D, 0x42, 154 | 0x00, 0x01, 0x45, 0x7C, 0x40, 155 | 0xF0, 0x29, 0x24, 0x29, 0xF0, 156 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 157 | 0x7C, 0x54, 0x55, 0x45, 0x00, 158 | 0x20, 0x54, 0x54, 0x7C, 0x54, 159 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 160 | 0x32, 0x49, 0x49, 0x49, 0x32, 161 | 0x32, 0x48, 0x48, 0x48, 0x32, 162 | 0x32, 0x4A, 0x48, 0x48, 0x30, 163 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 164 | 0x3A, 0x42, 0x40, 0x20, 0x78, 165 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 166 | 0x39, 0x44, 0x44, 0x44, 0x39, 167 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 168 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 169 | 0x48, 0x7E, 0x49, 0x43, 0x66, 170 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 171 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 172 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 173 | 0x20, 0x54, 0x54, 0x79, 0x41, 174 | 0x00, 0x00, 0x44, 0x7D, 0x41, 175 | 0x30, 0x48, 0x48, 0x4A, 0x32, 176 | 0x38, 0x40, 0x40, 0x22, 0x7A, 177 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 178 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 179 | 0x26, 0x29, 0x29, 0x2F, 0x28, 180 | 0x26, 0x29, 0x29, 0x29, 0x26, 181 | 0x30, 0x48, 0x4D, 0x40, 0x20, 182 | 0x38, 0x08, 0x08, 0x08, 0x08, 183 | 0x08, 0x08, 0x08, 0x08, 0x38, 184 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 185 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 186 | 0x00, 0x00, 0x7B, 0x00, 0x00, 187 | 0x08, 0x14, 0x2A, 0x14, 0x22, 188 | 0x22, 0x14, 0x2A, 0x14, 0x08, 189 | 0xAA, 0x00, 0x55, 0x00, 0xAA, 190 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, 191 | 0x00, 0x00, 0x00, 0xFF, 0x00, 192 | 0x10, 0x10, 0x10, 0xFF, 0x00, 193 | 0x14, 0x14, 0x14, 0xFF, 0x00, 194 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 195 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 196 | 0x14, 0x14, 0x14, 0xFC, 0x00, 197 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 198 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 199 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 200 | 0x14, 0x14, 0x17, 0x10, 0x1F, 201 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 202 | 0x14, 0x14, 0x14, 0x1F, 0x00, 203 | 0x10, 0x10, 0x10, 0xF0, 0x00, 204 | 0x00, 0x00, 0x00, 0x1F, 0x10, 205 | 0x10, 0x10, 0x10, 0x1F, 0x10, 206 | 0x10, 0x10, 0x10, 0xF0, 0x10, 207 | 0x00, 0x00, 0x00, 0xFF, 0x10, 208 | 0x10, 0x10, 0x10, 0x10, 0x10, 209 | 0x10, 0x10, 0x10, 0xFF, 0x10, 210 | 0x00, 0x00, 0x00, 0xFF, 0x14, 211 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 212 | 0x00, 0x00, 0x1F, 0x10, 0x17, 213 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 214 | 0x14, 0x14, 0x17, 0x10, 0x17, 215 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 216 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 217 | 0x14, 0x14, 0x14, 0x14, 0x14, 218 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 219 | 0x14, 0x14, 0x14, 0x17, 0x14, 220 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 221 | 0x14, 0x14, 0x14, 0xF4, 0x14, 222 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 223 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 224 | 0x00, 0x00, 0x00, 0x1F, 0x14, 225 | 0x00, 0x00, 0x00, 0xFC, 0x14, 226 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 227 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 228 | 0x14, 0x14, 0x14, 0xFF, 0x14, 229 | 0x10, 0x10, 0x10, 0x1F, 0x00, 230 | 0x00, 0x00, 0x00, 0xF0, 0x10, 231 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 232 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 233 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 234 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 235 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 236 | 0x38, 0x44, 0x44, 0x38, 0x44, 237 | 0x7C, 0x2A, 0x2A, 0x3E, 0x14, 238 | 0x7E, 0x02, 0x02, 0x06, 0x06, 239 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 240 | 0x63, 0x55, 0x49, 0x41, 0x63, 241 | 0x38, 0x44, 0x44, 0x3C, 0x04, 242 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 243 | 0x06, 0x02, 0x7E, 0x02, 0x02, 244 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 245 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 246 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 247 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 248 | 0x30, 0x48, 0x78, 0x48, 0x30, 249 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 250 | 0x3E, 0x49, 0x49, 0x49, 0x00, 251 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 252 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 253 | 0x44, 0x44, 0x5F, 0x44, 0x44, 254 | 0x40, 0x51, 0x4A, 0x44, 0x40, 255 | 0x40, 0x44, 0x4A, 0x51, 0x40, 256 | 0x00, 0x00, 0xFF, 0x01, 0x03, 257 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 258 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 259 | 0x36, 0x12, 0x36, 0x24, 0x36, 260 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 261 | 0x00, 0x00, 0x18, 0x18, 0x00, 262 | 0x00, 0x00, 0x10, 0x10, 0x00, 263 | 0x30, 0x40, 0xFF, 0x01, 0x01, 264 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 265 | 0x00, 0x19, 0x1D, 0x17, 0x12, 266 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 267 | 0x00, 0x00, 0x00, 0x00, 0x00, 268 | }; 269 | #endif 270 | -------------------------------------------------------------------------------- /src/utility/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Adafruit_GFX 3 | # and Adafruit_ST7735 4 | ####################################### 5 | 6 | ####################################### 7 | # Datatypes (KEYWORD1) 8 | ####################################### 9 | 10 | Adafruit_GFX KEYWORD1 11 | Adafruit_ST7735 KEYWORD1 12 | PImage KEYWORD1 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | drawPixel KEYWORD2 19 | invertDisplay KEYWORD2 20 | drawLine KEYWORD2 21 | drawFastVLine KEYWORD2 22 | drawFastHLine KEYWORD2 23 | drawRect KEYWORD2 24 | fillRect KEYWORD2 25 | fillScreen KEYWORD2 26 | drawCircle KEYWORD2 27 | drawCircleHelper KEYWORD2 28 | fillCircle KEYWORD2 29 | fillCircleHelper KEYWORD2 30 | drawTriangle KEYWORD2 31 | fillTriangle KEYWORD2 32 | drawRoundRect KEYWORD2 33 | fillRoundRect KEYWORD2 34 | drawBitmap KEYWORD2 35 | drawChar KEYWORD2 36 | setCursor KEYWORD2 37 | setTextColor KEYWORD2 38 | setTextSize KEYWORD2 39 | setTextWrap KEYWORD2 40 | height KEYWORD2 41 | width KEYWORD2 42 | setRotation KEYWORD2 43 | getRotation KEYWORD2 44 | 45 | 46 | 47 | newColor KEYWORD2 48 | background KEYWORD2 49 | fill KEYWORD2 50 | noFill KEYWORD2 51 | stroke KEYWORD2 52 | noStroke KEYWORD2 53 | text KEYWORD2 54 | textWrap KEYWORD2 55 | textSize KEYWORD2 56 | circle KEYWORD2 57 | point KEYWORD2 58 | quad KEYWORD2 59 | rect KEYWORD2 60 | triangle KEYWORD2 61 | loadImage KEYWORD2 62 | image KEYWORD2 63 | 64 | draw KEYWORD2 65 | isValid KEYWORD2 66 | 67 | ####################################### 68 | # Constants (LITERAL1) 69 | ####################################### 70 | 71 | --------------------------------------------------------------------------------