├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── lib ├── Adafruit_GFX_Library │ ├── Adafruit_GFX.cpp │ ├── Adafruit_GFX.h │ ├── gfxfont.h │ └── glcdfont.c ├── Adafruit_SSD1306-esp8266-64x48 │ ├── Adafruit_SSD1306.cpp │ ├── Adafruit_SSD1306.h │ ├── README.md │ ├── README.txt │ ├── examples │ │ ├── ssd1306_128x32_i2c │ │ │ └── ssd1306_128x32_i2c.ino │ │ ├── ssd1306_128x32_spi │ │ │ └── ssd1306_128x32_spi.ino │ │ ├── ssd1306_128x64_i2c │ │ │ └── ssd1306_128x64_i2c.ino │ │ ├── ssd1306_128x64_spi │ │ │ └── ssd1306_128x64_spi.ino │ │ └── ssd1306_64x48_i2c │ │ │ └── ssd1306_64x48_i2c.ino │ ├── library.properties │ └── license.txt └── readme.txt ├── platformio.ini ├── server-script └── weather_script.php └── src └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .clang_complete 3 | .gcc-flags.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < http://docs.platformio.org/en/latest/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < http://docs.platformio.org/en/latest/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choice one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # 39 | # script: 40 | # - platformio run 41 | 42 | 43 | # 44 | # Template #2: The project is intended to by used as a library with examples 45 | # 46 | 47 | # language: python 48 | # python: 49 | # - "2.7" 50 | # 51 | # sudo: false 52 | # cache: 53 | # directories: 54 | # - "~/.platformio" 55 | # 56 | # env: 57 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 58 | # - PLATFORMIO_CI_SRC=examples/file.ino 59 | # - PLATFORMIO_CI_SRC=path/to/test/directory 60 | # 61 | # install: 62 | # - pip install -U platformio 63 | # 64 | # script: 65 | # - platformio ci --lib="." --board=TYPE_1 --board=TYPE_2 --board=TYPE_N 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MeteoESP 2 | ## Weather Station for Wemos D1 mini with official 64x48 OLED shield 3 | 4 | ### Project is created in _PlatformIO IDE_ 5 | http://platformio.org/platformio-ide 6 | 7 | There you can install libraries directly via console command in the IDE. 8 | Find libs here http://platformio.org/lib and install for example: `> platformio lib install 13` to install _Adafruit GFX library_ (not needed...) Then you need some hosting space, for the server-side script which parses data for Wemos D1 mini. It's a tiny PHP script. If you don't have any hosting space, you can register for any of the free hosting services. You'll also need to fill in _Wunderground API_ key (free registration needed) and location ID in the PHP source file on the server. The PHP script is in directory `server-script`. Copy it to server for example with Filezilla client. 9 | 10 | #### [Working example video here](https://youtu.be/ubzbj7ghyDk) 11 | -------------------------------------------------------------------------------- /lib/Adafruit_GFX_Library/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 | #ifdef __AVR__ 35 | #include 36 | #elif defined(ESP8266) 37 | #include 38 | #endif 39 | #include "Adafruit_GFX.h" 40 | #include "glcdfont.c" 41 | 42 | // Many (but maybe not all) non-AVR board installs define macros 43 | // for compatibility with existing PROGMEM-reading AVR code. 44 | // Do our own checks and defines here for good measure... 45 | 46 | #ifndef pgm_read_byte 47 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 48 | #endif 49 | #ifndef pgm_read_word 50 | #define pgm_read_word(addr) (*(const unsigned short *)(addr)) 51 | #endif 52 | #ifndef pgm_read_dword 53 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) 54 | #endif 55 | 56 | // Pointers are a peculiar case...typically 16-bit on AVR boards, 57 | // 32 bits elsewhere. Try to accommodate both... 58 | 59 | #if !defined(__INT_MAX__) || (__INT_MAX__ > 0xFFFF) 60 | #define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr)) 61 | #else 62 | #define pgm_read_pointer(addr) ((void *)pgm_read_word(addr)) 63 | #endif 64 | 65 | #ifndef min 66 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 67 | #endif 68 | 69 | #ifndef _swap_int16_t 70 | #define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; } 71 | #endif 72 | 73 | Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h): 74 | WIDTH(w), HEIGHT(h) 75 | { 76 | _width = WIDTH; 77 | _height = HEIGHT; 78 | rotation = 0; 79 | cursor_y = cursor_x = 0; 80 | textsize = 1; 81 | textcolor = textbgcolor = 0xFFFF; 82 | wrap = true; 83 | _cp437 = false; 84 | gfxFont = NULL; 85 | } 86 | 87 | // Draw a circle outline 88 | void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, 89 | uint16_t color) { 90 | int16_t f = 1 - r; 91 | int16_t ddF_x = 1; 92 | int16_t ddF_y = -2 * r; 93 | int16_t x = 0; 94 | int16_t y = r; 95 | 96 | drawPixel(x0 , y0+r, color); 97 | drawPixel(x0 , y0-r, color); 98 | drawPixel(x0+r, y0 , color); 99 | drawPixel(x0-r, y0 , color); 100 | 101 | while (x= 0) { 103 | y--; 104 | ddF_y += 2; 105 | f += ddF_y; 106 | } 107 | x++; 108 | ddF_x += 2; 109 | f += ddF_x; 110 | 111 | drawPixel(x0 + x, y0 + y, color); 112 | drawPixel(x0 - x, y0 + y, color); 113 | drawPixel(x0 + x, y0 - y, color); 114 | drawPixel(x0 - x, y0 - y, color); 115 | drawPixel(x0 + y, y0 + x, color); 116 | drawPixel(x0 - y, y0 + x, color); 117 | drawPixel(x0 + y, y0 - x, color); 118 | drawPixel(x0 - y, y0 - x, color); 119 | } 120 | } 121 | 122 | void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, 123 | int16_t r, uint8_t cornername, uint16_t color) { 124 | int16_t f = 1 - r; 125 | int16_t ddF_x = 1; 126 | int16_t ddF_y = -2 * r; 127 | int16_t x = 0; 128 | int16_t y = r; 129 | 130 | while (x= 0) { 132 | y--; 133 | ddF_y += 2; 134 | f += ddF_y; 135 | } 136 | x++; 137 | ddF_x += 2; 138 | f += ddF_x; 139 | if (cornername & 0x4) { 140 | drawPixel(x0 + x, y0 + y, color); 141 | drawPixel(x0 + y, y0 + x, color); 142 | } 143 | if (cornername & 0x2) { 144 | drawPixel(x0 + x, y0 - y, color); 145 | drawPixel(x0 + y, y0 - x, color); 146 | } 147 | if (cornername & 0x8) { 148 | drawPixel(x0 - y, y0 + x, color); 149 | drawPixel(x0 - x, y0 + y, color); 150 | } 151 | if (cornername & 0x1) { 152 | drawPixel(x0 - y, y0 - x, color); 153 | drawPixel(x0 - x, y0 - y, color); 154 | } 155 | } 156 | } 157 | 158 | void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, 159 | uint16_t color) { 160 | drawFastVLine(x0, y0-r, 2*r+1, color); 161 | fillCircleHelper(x0, y0, r, 3, 0, color); 162 | } 163 | 164 | // Used to do circles and roundrects 165 | void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 166 | uint8_t cornername, int16_t delta, uint16_t color) { 167 | 168 | int16_t f = 1 - r; 169 | int16_t ddF_x = 1; 170 | int16_t ddF_y = -2 * r; 171 | int16_t x = 0; 172 | int16_t y = r; 173 | 174 | while (x= 0) { 176 | y--; 177 | ddF_y += 2; 178 | f += ddF_y; 179 | } 180 | x++; 181 | ddF_x += 2; 182 | f += ddF_x; 183 | 184 | if (cornername & 0x1) { 185 | drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); 186 | drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); 187 | } 188 | if (cornername & 0x2) { 189 | drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); 190 | drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); 191 | } 192 | } 193 | } 194 | 195 | // Bresenham's algorithm - thx wikpedia 196 | void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 197 | uint16_t color) { 198 | int16_t steep = abs(y1 - y0) > abs(x1 - x0); 199 | if (steep) { 200 | _swap_int16_t(x0, y0); 201 | _swap_int16_t(x1, y1); 202 | } 203 | 204 | if (x0 > x1) { 205 | _swap_int16_t(x0, x1); 206 | _swap_int16_t(y0, y1); 207 | } 208 | 209 | int16_t dx, dy; 210 | dx = x1 - x0; 211 | dy = abs(y1 - y0); 212 | 213 | int16_t err = dx / 2; 214 | int16_t ystep; 215 | 216 | if (y0 < y1) { 217 | ystep = 1; 218 | } else { 219 | ystep = -1; 220 | } 221 | 222 | for (; x0<=x1; x0++) { 223 | if (steep) { 224 | drawPixel(y0, x0, color); 225 | } else { 226 | drawPixel(x0, y0, color); 227 | } 228 | err -= dy; 229 | if (err < 0) { 230 | y0 += ystep; 231 | err += dx; 232 | } 233 | } 234 | } 235 | 236 | // Draw a rectangle 237 | void Adafruit_GFX::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, 238 | uint16_t color) { 239 | drawFastHLine(x, y, w, color); 240 | drawFastHLine(x, y+h-1, w, color); 241 | drawFastVLine(x, y, h, color); 242 | drawFastVLine(x+w-1, y, h, color); 243 | } 244 | 245 | void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, 246 | int16_t h, uint16_t color) { 247 | // Update in subclasses if desired! 248 | drawLine(x, y, x, y+h-1, color); 249 | } 250 | 251 | void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, 252 | int16_t w, uint16_t color) { 253 | // Update in subclasses if desired! 254 | drawLine(x, y, x+w-1, y, color); 255 | } 256 | 257 | void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 258 | uint16_t color) { 259 | // Update in subclasses if desired! 260 | for (int16_t i=x; i= y1 >= y0) 310 | if (y0 > y1) { 311 | _swap_int16_t(y0, y1); _swap_int16_t(x0, x1); 312 | } 313 | if (y1 > y2) { 314 | _swap_int16_t(y2, y1); _swap_int16_t(x2, x1); 315 | } 316 | if (y0 > y1) { 317 | _swap_int16_t(y0, y1); _swap_int16_t(x0, x1); 318 | } 319 | 320 | if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing 321 | a = b = x0; 322 | if(x1 < a) a = x1; 323 | else if(x1 > b) b = x1; 324 | if(x2 < a) a = x2; 325 | else if(x2 > b) b = x2; 326 | drawFastHLine(a, y0, b-a+1, color); 327 | return; 328 | } 329 | 330 | int16_t 331 | dx01 = x1 - x0, 332 | dy01 = y1 - y0, 333 | dx02 = x2 - x0, 334 | dy02 = y2 - y0, 335 | dx12 = x2 - x1, 336 | dy12 = y2 - y1; 337 | int32_t 338 | sa = 0, 339 | sb = 0; 340 | 341 | // For upper part of triangle, find scanline crossings for segments 342 | // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 343 | // is included here (and second loop will be skipped, avoiding a /0 344 | // error there), otherwise scanline y1 is skipped here and handled 345 | // in the second loop...which also avoids a /0 error here if y0=y1 346 | // (flat-topped triangle). 347 | if(y1 == y2) last = y1; // Include y1 scanline 348 | else last = y1-1; // Skip it 349 | 350 | for(y=y0; y<=last; y++) { 351 | a = x0 + sa / dy01; 352 | b = x0 + sb / dy02; 353 | sa += dx01; 354 | sb += dx02; 355 | /* longhand: 356 | a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); 357 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 358 | */ 359 | if(a > b) _swap_int16_t(a,b); 360 | drawFastHLine(a, y, b-a+1, color); 361 | } 362 | 363 | // For lower part of triangle, find scanline crossings for segments 364 | // 0-2 and 1-2. This loop is skipped if y1=y2. 365 | sa = dx12 * (y - y1); 366 | sb = dx02 * (y - y0); 367 | for(; y<=y2; y++) { 368 | a = x1 + sa / dy12; 369 | b = x0 + sb / dy02; 370 | sa += dx12; 371 | sb += dx02; 372 | /* longhand: 373 | a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); 374 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 375 | */ 376 | if(a > b) _swap_int16_t(a,b); 377 | drawFastHLine(a, y, b-a+1, color); 378 | } 379 | } 380 | 381 | // Draw a 1-bit image (bitmap) at the specified (x,y) position from the 382 | // provided bitmap buffer (must be PROGMEM memory) using the specified 383 | // foreground color (unset bits are transparent). 384 | void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, 385 | const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) { 386 | 387 | int16_t i, j, byteWidth = (w + 7) / 8; 388 | uint8_t byte; 389 | 390 | for(j=0; j>= 1; 463 | else byte = pgm_read_byte(bitmap + j * byteWidth + i / 8); 464 | if(byte & 0x01) drawPixel(x+i, y+j, color); 465 | } 466 | } 467 | } 468 | 469 | #if ARDUINO >= 100 470 | size_t Adafruit_GFX::write(uint8_t c) { 471 | #else 472 | void Adafruit_GFX::write(uint8_t c) { 473 | #endif 474 | 475 | if(!gfxFont) { // 'Classic' built-in font 476 | 477 | if(c == '\n') { 478 | cursor_y += textsize*8; 479 | cursor_x = 0; 480 | } else if(c == '\r') { 481 | // skip em 482 | } else { 483 | if(wrap && ((cursor_x + textsize * 6) >= _width)) { // Heading off edge? 484 | cursor_x = 0; // Reset x to zero 485 | cursor_y += textsize * 8; // Advance y one line 486 | } 487 | drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); 488 | cursor_x += textsize * 6; 489 | } 490 | 491 | } else { // Custom font 492 | 493 | if(c == '\n') { 494 | cursor_x = 0; 495 | cursor_y += (int16_t)textsize * 496 | (uint8_t)pgm_read_byte(&gfxFont->yAdvance); 497 | } else if(c != '\r') { 498 | uint8_t first = pgm_read_byte(&gfxFont->first); 499 | if((c >= first) && (c <= (uint8_t)pgm_read_byte(&gfxFont->last))) { 500 | uint8_t c2 = c - pgm_read_byte(&gfxFont->first); 501 | GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c2]); 502 | uint8_t w = pgm_read_byte(&glyph->width), 503 | h = pgm_read_byte(&glyph->height); 504 | if((w > 0) && (h > 0)) { // Is there an associated bitmap? 505 | int16_t xo = (int8_t)pgm_read_byte(&glyph->xOffset); // sic 506 | if(wrap && ((cursor_x + textsize * (xo + w)) >= _width)) { 507 | // Drawing character would go off right edge; wrap to new line 508 | cursor_x = 0; 509 | cursor_y += (int16_t)textsize * 510 | (uint8_t)pgm_read_byte(&gfxFont->yAdvance); 511 | } 512 | drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); 513 | } 514 | cursor_x += pgm_read_byte(&glyph->xAdvance) * (int16_t)textsize; 515 | } 516 | } 517 | 518 | } 519 | #if ARDUINO >= 100 520 | return 1; 521 | #endif 522 | } 523 | 524 | // Draw a character 525 | void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, 526 | uint16_t color, uint16_t bg, uint8_t size) { 527 | 528 | if(!gfxFont) { // 'Classic' built-in font 529 | 530 | if((x >= _width) || // Clip right 531 | (y >= _height) || // Clip bottom 532 | ((x + 6 * size - 1) < 0) || // Clip left 533 | ((y + 8 * size - 1) < 0)) // Clip top 534 | return; 535 | 536 | if(!_cp437 && (c >= 176)) c++; // Handle 'classic' charset behavior 537 | 538 | for(int8_t i=0; i<6; i++ ) { 539 | uint8_t line; 540 | if(i < 5) line = pgm_read_byte(font+(c*5)+i); 541 | else line = 0x0; 542 | for(int8_t j=0; j<8; j++, line >>= 1) { 543 | if(line & 0x1) { 544 | if(size == 1) drawPixel(x+i, y+j, color); 545 | else fillRect(x+(i*size), y+(j*size), size, size, color); 546 | } else if(bg != color) { 547 | if(size == 1) drawPixel(x+i, y+j, bg); 548 | else fillRect(x+i*size, y+j*size, size, size, bg); 549 | } 550 | } 551 | } 552 | 553 | } else { // Custom font 554 | 555 | // Character is assumed previously filtered by write() to eliminate 556 | // newlines, returns, non-printable characters, etc. Calling drawChar() 557 | // directly with 'bad' characters of font may cause mayhem! 558 | 559 | c -= pgm_read_byte(&gfxFont->first); 560 | GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]); 561 | uint8_t *bitmap = (uint8_t *)pgm_read_pointer(&gfxFont->bitmap); 562 | 563 | uint16_t bo = pgm_read_word(&glyph->bitmapOffset); 564 | uint8_t w = pgm_read_byte(&glyph->width), 565 | h = pgm_read_byte(&glyph->height), 566 | xa = pgm_read_byte(&glyph->xAdvance); 567 | int8_t xo = pgm_read_byte(&glyph->xOffset), 568 | yo = pgm_read_byte(&glyph->yOffset); 569 | uint8_t xx, yy, bits, bit = 0; 570 | int16_t xo16, yo16; 571 | 572 | if(size > 1) { 573 | xo16 = xo; 574 | yo16 = yo; 575 | } 576 | 577 | // Todo: Add character clipping here 578 | 579 | // NOTE: THERE IS NO 'BACKGROUND' COLOR OPTION ON CUSTOM FONTS. 580 | // THIS IS ON PURPOSE AND BY DESIGN. The background color feature 581 | // has typically been used with the 'classic' font to overwrite old 582 | // screen contents with new data. This ONLY works because the 583 | // characters are a uniform size; it's not a sensible thing to do with 584 | // proportionally-spaced fonts with glyphs of varying sizes (and that 585 | // may overlap). To replace previously-drawn text when using a custom 586 | // font, use the getTextBounds() function to determine the smallest 587 | // rectangle encompassing a string, erase the area with fillRect(), 588 | // then draw new text. This WILL infortunately 'blink' the text, but 589 | // is unavoidable. Drawing 'background' pixels will NOT fix this, 590 | // only creates a new set of problems. Have an idea to work around 591 | // this (a canvas object type for MCUs that can afford the RAM and 592 | // displays supporting setAddrWindow() and pushColors()), but haven't 593 | // implemented this yet. 594 | 595 | for(yy=0; yy 0) ? s : 1; 629 | } 630 | 631 | void Adafruit_GFX::setTextColor(uint16_t c) { 632 | // For 'transparent' background, we'll set the bg 633 | // to the same as fg instead of using a flag 634 | textcolor = textbgcolor = c; 635 | } 636 | 637 | void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) { 638 | textcolor = c; 639 | textbgcolor = b; 640 | } 641 | 642 | void Adafruit_GFX::setTextWrap(boolean w) { 643 | wrap = w; 644 | } 645 | 646 | uint8_t Adafruit_GFX::getRotation(void) const { 647 | return rotation; 648 | } 649 | 650 | void Adafruit_GFX::setRotation(uint8_t x) { 651 | rotation = (x & 3); 652 | switch(rotation) { 653 | case 0: 654 | case 2: 655 | _width = WIDTH; 656 | _height = HEIGHT; 657 | break; 658 | case 1: 659 | case 3: 660 | _width = HEIGHT; 661 | _height = WIDTH; 662 | break; 663 | } 664 | } 665 | 666 | // Enable (or disable) Code Page 437-compatible charset. 667 | // There was an error in glcdfont.c for the longest time -- one character 668 | // (#176, the 'light shade' block) was missing -- this threw off the index 669 | // of every character that followed it. But a TON of code has been written 670 | // with the erroneous character indices. By default, the library uses the 671 | // original 'wrong' behavior and old sketches will still work. Pass 'true' 672 | // to this function to use correct CP437 character values in your code. 673 | void Adafruit_GFX::cp437(boolean x) { 674 | _cp437 = x; 675 | } 676 | 677 | void Adafruit_GFX::setFont(const GFXfont *f) { 678 | if(f) { // Font struct pointer passed in? 679 | if(!gfxFont) { // And no current font struct? 680 | // Switching from classic to new font behavior. 681 | // Move cursor pos down 6 pixels so it's on baseline. 682 | cursor_y += 6; 683 | } 684 | } else if(gfxFont) { // NULL passed. Current font struct defined? 685 | // Switching from new to classic font behavior. 686 | // Move cursor pos up 6 pixels so it's at top-left of char. 687 | cursor_y -= 6; 688 | } 689 | gfxFont = (GFXfont *)f; 690 | } 691 | 692 | // Pass string and a cursor position, returns UL corner and W,H. 693 | void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y, 694 | int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) { 695 | uint8_t c; // Current character 696 | 697 | *x1 = x; 698 | *y1 = y; 699 | *w = *h = 0; 700 | 701 | if(gfxFont) { 702 | 703 | GFXglyph *glyph; 704 | uint8_t first = pgm_read_byte(&gfxFont->first), 705 | last = pgm_read_byte(&gfxFont->last), 706 | gw, gh, xa; 707 | int8_t xo, yo; 708 | int16_t minx = _width, miny = _height, maxx = -1, maxy = -1, 709 | gx1, gy1, gx2, gy2, ts = (int16_t)textsize, 710 | ya = ts * (uint8_t)pgm_read_byte(&gfxFont->yAdvance); 711 | 712 | while((c = *str++)) { 713 | if(c != '\n') { // Not a newline 714 | if(c != '\r') { // Not a carriage return, is normal char 715 | if((c >= first) && (c <= last)) { // Char present in current font 716 | c -= first; 717 | glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]); 718 | gw = pgm_read_byte(&glyph->width); 719 | gh = pgm_read_byte(&glyph->height); 720 | xa = pgm_read_byte(&glyph->xAdvance); 721 | xo = pgm_read_byte(&glyph->xOffset); 722 | yo = pgm_read_byte(&glyph->yOffset); 723 | if(wrap && ((x + (((int16_t)xo + gw) * ts)) >= _width)) { 724 | // Line wrap 725 | x = 0; // Reset x to 0 726 | y += ya; // Advance y by 1 line 727 | } 728 | gx1 = x + xo * ts; 729 | gy1 = y + yo * ts; 730 | gx2 = gx1 + gw * ts - 1; 731 | gy2 = gy1 + gh * ts - 1; 732 | if(gx1 < minx) minx = gx1; 733 | if(gy1 < miny) miny = gy1; 734 | if(gx2 > maxx) maxx = gx2; 735 | if(gy2 > maxy) maxy = gy2; 736 | x += xa * ts; 737 | } 738 | } // Carriage return = do nothing 739 | } else { // Newline 740 | x = 0; // Reset x 741 | y += ya; // Advance y by 1 line 742 | } 743 | } 744 | // End of string 745 | *x1 = minx; 746 | *y1 = miny; 747 | if(maxx >= minx) *w = maxx - minx + 1; 748 | if(maxy >= miny) *h = maxy - miny + 1; 749 | 750 | } else { // Default font 751 | 752 | uint16_t lineWidth = 0, maxWidth = 0; // Width of current, all lines 753 | 754 | while((c = *str++)) { 755 | if(c != '\n') { // Not a newline 756 | if(c != '\r') { // Not a carriage return, is normal char 757 | if(wrap && ((x + textsize * 6) >= _width)) { 758 | x = 0; // Reset x to 0 759 | y += textsize * 8; // Advance y by 1 line 760 | if(lineWidth > maxWidth) maxWidth = lineWidth; // Save widest line 761 | lineWidth = textsize * 6; // First char on new line 762 | } else { // No line wrap, just keep incrementing X 763 | lineWidth += textsize * 6; // Includes interchar x gap 764 | } 765 | } // Carriage return = do nothing 766 | } else { // Newline 767 | x = 0; // Reset x to 0 768 | y += textsize * 8; // Advance y by 1 line 769 | if(lineWidth > maxWidth) maxWidth = lineWidth; // Save widest line 770 | lineWidth = 0; // Reset lineWidth for new line 771 | } 772 | } 773 | // End of string 774 | if(lineWidth) y += textsize * 8; // Add height of last (or only) line 775 | *w = maxWidth - 1; // Don't include last interchar x gap 776 | *h = y - *y1; 777 | 778 | } // End classic vs custom font 779 | } 780 | 781 | // Same as above, but for PROGMEM strings 782 | void Adafruit_GFX::getTextBounds(const __FlashStringHelper *str, 783 | int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) { 784 | uint8_t *s = (uint8_t *)str, c; 785 | 786 | *x1 = x; 787 | *y1 = y; 788 | *w = *h = 0; 789 | 790 | if(gfxFont) { 791 | 792 | GFXglyph *glyph; 793 | uint8_t first = pgm_read_byte(&gfxFont->first), 794 | last = pgm_read_byte(&gfxFont->last), 795 | gw, gh, xa; 796 | int8_t xo, yo; 797 | int16_t minx = _width, miny = _height, maxx = -1, maxy = -1, 798 | gx1, gy1, gx2, gy2, ts = (int16_t)textsize, 799 | ya = ts * (uint8_t)pgm_read_byte(&gfxFont->yAdvance); 800 | 801 | while((c = pgm_read_byte(s++))) { 802 | if(c != '\n') { // Not a newline 803 | if(c != '\r') { // Not a carriage return, is normal char 804 | if((c >= first) && (c <= last)) { // Char present in current font 805 | c -= first; 806 | glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]); 807 | gw = pgm_read_byte(&glyph->width); 808 | gh = pgm_read_byte(&glyph->height); 809 | xa = pgm_read_byte(&glyph->xAdvance); 810 | xo = pgm_read_byte(&glyph->xOffset); 811 | yo = pgm_read_byte(&glyph->yOffset); 812 | if(wrap && ((x + (((int16_t)xo + gw) * ts)) >= _width)) { 813 | // Line wrap 814 | x = 0; // Reset x to 0 815 | y += ya; // Advance y by 1 line 816 | } 817 | gx1 = x + xo * ts; 818 | gy1 = y + yo * ts; 819 | gx2 = gx1 + gw * ts - 1; 820 | gy2 = gy1 + gh * ts - 1; 821 | if(gx1 < minx) minx = gx1; 822 | if(gy1 < miny) miny = gy1; 823 | if(gx2 > maxx) maxx = gx2; 824 | if(gy2 > maxy) maxy = gy2; 825 | x += xa * ts; 826 | } 827 | } // Carriage return = do nothing 828 | } else { // Newline 829 | x = 0; // Reset x 830 | y += ya; // Advance y by 1 line 831 | } 832 | } 833 | // End of string 834 | *x1 = minx; 835 | *y1 = miny; 836 | if(maxx >= minx) *w = maxx - minx + 1; 837 | if(maxy >= miny) *h = maxy - miny + 1; 838 | 839 | } else { // Default font 840 | 841 | uint16_t lineWidth = 0, maxWidth = 0; // Width of current, all lines 842 | 843 | while((c = pgm_read_byte(s++))) { 844 | if(c != '\n') { // Not a newline 845 | if(c != '\r') { // Not a carriage return, is normal char 846 | if(wrap && ((x + textsize * 6) >= _width)) { 847 | x = 0; // Reset x to 0 848 | y += textsize * 8; // Advance y by 1 line 849 | if(lineWidth > maxWidth) maxWidth = lineWidth; // Save widest line 850 | lineWidth = textsize * 6; // First char on new line 851 | } else { // No line wrap, just keep incrementing X 852 | lineWidth += textsize * 6; // Includes interchar x gap 853 | } 854 | } // Carriage return = do nothing 855 | } else { // Newline 856 | x = 0; // Reset x to 0 857 | y += textsize * 8; // Advance y by 1 line 858 | if(lineWidth > maxWidth) maxWidth = lineWidth; // Save widest line 859 | lineWidth = 0; // Reset lineWidth for new line 860 | } 861 | } 862 | // End of string 863 | if(lineWidth) y += textsize * 8; // Add height of last (or only) line 864 | *w = maxWidth - 1; // Don't include last interchar x gap 865 | *h = y - *y1; 866 | 867 | } // End classic vs custom font 868 | } 869 | 870 | // Return the size of the display (per current rotation) 871 | int16_t Adafruit_GFX::width(void) const { 872 | return _width; 873 | } 874 | 875 | int16_t Adafruit_GFX::height(void) const { 876 | return _height; 877 | } 878 | 879 | void Adafruit_GFX::invertDisplay(boolean i) { 880 | // Do nothing, must be subclassed if supported by hardware 881 | } 882 | 883 | /***************************************************************************/ 884 | // code for the GFX button UI element 885 | 886 | Adafruit_GFX_Button::Adafruit_GFX_Button(void) { 887 | _gfx = 0; 888 | } 889 | 890 | void Adafruit_GFX_Button::initButton( 891 | Adafruit_GFX *gfx, int16_t x, int16_t y, uint8_t w, uint8_t h, 892 | uint16_t outline, uint16_t fill, uint16_t textcolor, 893 | char *label, uint8_t textsize) 894 | { 895 | _x = x; 896 | _y = y; 897 | _w = w; 898 | _h = h; 899 | _outlinecolor = outline; 900 | _fillcolor = fill; 901 | _textcolor = textcolor; 902 | _textsize = textsize; 903 | _gfx = gfx; 904 | strncpy(_label, label, 9); 905 | _label[9] = 0; 906 | } 907 | 908 | void Adafruit_GFX_Button::drawButton(boolean inverted) { 909 | uint16_t fill, outline, text; 910 | 911 | if(!inverted) { 912 | fill = _fillcolor; 913 | outline = _outlinecolor; 914 | text = _textcolor; 915 | } else { 916 | fill = _textcolor; 917 | outline = _outlinecolor; 918 | text = _fillcolor; 919 | } 920 | 921 | _gfx->fillRoundRect(_x - (_w/2), _y - (_h/2), _w, _h, min(_w,_h)/4, fill); 922 | _gfx->drawRoundRect(_x - (_w/2), _y - (_h/2), _w, _h, min(_w,_h)/4, outline); 923 | 924 | _gfx->setCursor(_x - strlen(_label)*3*_textsize, _y-4*_textsize); 925 | _gfx->setTextColor(text); 926 | _gfx->setTextSize(_textsize); 927 | _gfx->print(_label); 928 | } 929 | 930 | boolean Adafruit_GFX_Button::contains(int16_t x, int16_t y) { 931 | if ((x < (_x - _w/2)) || (x > (_x + _w/2))) return false; 932 | if ((y < (_y - _h/2)) || (y > (_y + _h/2))) return false; 933 | return true; 934 | } 935 | 936 | void Adafruit_GFX_Button::press(boolean p) { 937 | laststate = currstate; 938 | currstate = p; 939 | } 940 | 941 | boolean Adafruit_GFX_Button::isPressed() { return currstate; } 942 | boolean Adafruit_GFX_Button::justPressed() { return (currstate && !laststate); } 943 | boolean Adafruit_GFX_Button::justReleased() { return (!currstate && laststate); } 944 | 945 | // ------------------------------------------------------------------------- 946 | 947 | // GFXcanvas1 and GFXcanvas16 (currently a WIP, don't get too comfy with the 948 | // implementation) provide 1- and 16-bit offscreen canvases, the address of 949 | // which can be passed to drawBitmap() or pushColors() (the latter appears 950 | // to only be in Adafruit_TFTLCD at this time). This is here mostly to 951 | // help with the recently-added proportionally-spaced fonts; adds a way to 952 | // refresh a section of the screen without a massive flickering clear-and- 953 | // redraw...but maybe you'll find other uses too. VERY RAM-intensive, since 954 | // the buffer is in MCU memory and not the display driver...GXFcanvas1 might 955 | // be minimally useful on an Uno-class board, but this and GFXcanvas16 are 956 | // much more likely to require at least a Mega or various recent ARM-type 957 | // boards (recomment, as the text+bitmap draw can be pokey). GFXcanvas1 958 | // requires 1 bit per pixel (rounded up to nearest byte per scanline), 959 | // GFXcanvas16 requires 2 bytes per pixel (no scanline pad). 960 | // NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND. 961 | 962 | GFXcanvas1::GFXcanvas1(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) { 963 | uint16_t bytes = ((w + 7) / 8) * h; 964 | if((buffer = (uint8_t *)malloc(bytes))) { 965 | memset(buffer, 0, bytes); 966 | } 967 | } 968 | 969 | GFXcanvas1::~GFXcanvas1(void) { 970 | if(buffer) free(buffer); 971 | } 972 | 973 | uint8_t* GFXcanvas1::getBuffer(void) { 974 | return buffer; 975 | } 976 | 977 | void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) { 978 | // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR 979 | static const uint8_t PROGMEM 980 | GFXsetBit[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, 981 | GFXclrBit[] = { 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE }; 982 | 983 | if(buffer) { 984 | if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return; 985 | 986 | int16_t t; 987 | switch(rotation) { 988 | case 1: 989 | t = x; 990 | x = WIDTH - 1 - y; 991 | y = t; 992 | break; 993 | case 2: 994 | x = WIDTH - 1 - x; 995 | y = HEIGHT - 1 - y; 996 | break; 997 | case 3: 998 | t = x; 999 | x = y; 1000 | y = HEIGHT - 1 - t; 1001 | break; 1002 | } 1003 | 1004 | uint8_t *ptr = &buffer[(x / 8) + y * ((WIDTH + 7) / 8)]; 1005 | if(color) *ptr |= pgm_read_byte(&GFXsetBit[x & 7]); 1006 | else *ptr &= pgm_read_byte(&GFXclrBit[x & 7]); 1007 | } 1008 | } 1009 | 1010 | void GFXcanvas1::fillScreen(uint16_t color) { 1011 | if(buffer) { 1012 | uint16_t bytes = ((WIDTH + 7) / 8) * HEIGHT; 1013 | memset(buffer, color ? 0xFF : 0x00, bytes); 1014 | } 1015 | } 1016 | 1017 | GFXcanvas16::GFXcanvas16(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) { 1018 | uint16_t bytes = w * h * 2; 1019 | if((buffer = (uint16_t *)malloc(bytes))) { 1020 | memset(buffer, 0, bytes); 1021 | } 1022 | } 1023 | 1024 | GFXcanvas16::~GFXcanvas16(void) { 1025 | if(buffer) free(buffer); 1026 | } 1027 | 1028 | uint16_t* GFXcanvas16::getBuffer(void) { 1029 | return buffer; 1030 | } 1031 | 1032 | void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) { 1033 | if(buffer) { 1034 | if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return; 1035 | 1036 | int16_t t; 1037 | switch(rotation) { 1038 | case 1: 1039 | t = x; 1040 | x = WIDTH - 1 - y; 1041 | y = t; 1042 | break; 1043 | case 2: 1044 | x = WIDTH - 1 - x; 1045 | y = HEIGHT - 1 - y; 1046 | break; 1047 | case 3: 1048 | t = x; 1049 | x = y; 1050 | y = HEIGHT - 1 - t; 1051 | break; 1052 | } 1053 | 1054 | buffer[x + y * WIDTH] = color; 1055 | } 1056 | } 1057 | 1058 | void GFXcanvas16::fillScreen(uint16_t color) { 1059 | if(buffer) { 1060 | uint8_t hi = color >> 8, lo = color & 0xFF; 1061 | if(hi == lo) { 1062 | memset(buffer, lo, WIDTH * HEIGHT * 2); 1063 | } else { 1064 | uint16_t i, pixels = WIDTH * HEIGHT; 1065 | for(i=0; i= 100 5 | #include "Arduino.h" 6 | #include "Print.h" 7 | #else 8 | #include "WProgram.h" 9 | #endif 10 | 11 | #include "gfxfont.h" 12 | 13 | class Adafruit_GFX : public Print { 14 | 15 | public: 16 | 17 | Adafruit_GFX(int16_t w, int16_t h); // Constructor 18 | 19 | // This MUST be defined by the subclass: 20 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 21 | 22 | // These MAY be overridden by the subclass to provide device-specific 23 | // optimized code. Otherwise 'generic' versions are used. 24 | virtual void 25 | drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color), 26 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 27 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 28 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 29 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 30 | fillScreen(uint16_t color), 31 | invertDisplay(boolean i); 32 | 33 | // These exist only with Adafruit_GFX (no subclass overrides) 34 | void 35 | drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 36 | drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 37 | uint16_t color), 38 | fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 39 | fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 40 | int16_t delta, uint16_t color), 41 | drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 42 | int16_t x2, int16_t y2, uint16_t color), 43 | fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 44 | int16_t x2, int16_t y2, uint16_t color), 45 | drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 46 | int16_t radius, uint16_t color), 47 | fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 48 | int16_t radius, uint16_t color), 49 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 50 | int16_t w, int16_t h, uint16_t color), 51 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 52 | int16_t w, int16_t h, uint16_t color, uint16_t bg), 53 | drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, 54 | int16_t w, int16_t h, uint16_t color), 55 | drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, 56 | int16_t w, int16_t h, uint16_t color, uint16_t bg), 57 | drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 58 | int16_t w, int16_t h, uint16_t color), 59 | drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, 60 | uint16_t bg, uint8_t size), 61 | setCursor(int16_t x, int16_t y), 62 | setTextColor(uint16_t c), 63 | setTextColor(uint16_t c, uint16_t bg), 64 | setTextSize(uint8_t s), 65 | setTextWrap(boolean w), 66 | setRotation(uint8_t r), 67 | cp437(boolean x=true), 68 | setFont(const GFXfont *f = NULL), 69 | getTextBounds(char *string, int16_t x, int16_t y, 70 | int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h), 71 | getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y, 72 | int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h); 73 | 74 | #if ARDUINO >= 100 75 | virtual size_t write(uint8_t); 76 | #else 77 | virtual void write(uint8_t); 78 | #endif 79 | 80 | int16_t height(void) const; 81 | int16_t width(void) const; 82 | 83 | uint8_t getRotation(void) const; 84 | 85 | // get current cursor position (get rotation safe maximum values, using: width() for x, height() for y) 86 | int16_t getCursorX(void) const; 87 | int16_t getCursorY(void) const; 88 | 89 | protected: 90 | const int16_t 91 | WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes 92 | int16_t 93 | _width, _height, // Display w/h as modified by current rotation 94 | cursor_x, cursor_y; 95 | uint16_t 96 | textcolor, textbgcolor; 97 | uint8_t 98 | textsize, 99 | rotation; 100 | boolean 101 | wrap, // If set, 'wrap' text at right edge of display 102 | _cp437; // If set, use correct CP437 charset (default is off) 103 | GFXfont 104 | *gfxFont; 105 | }; 106 | 107 | class Adafruit_GFX_Button { 108 | 109 | public: 110 | Adafruit_GFX_Button(void); 111 | void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y, 112 | uint8_t w, uint8_t h, uint16_t outline, uint16_t fill, 113 | uint16_t textcolor, char *label, uint8_t textsize); 114 | void drawButton(boolean inverted = false); 115 | boolean contains(int16_t x, int16_t y); 116 | 117 | void press(boolean p); 118 | boolean isPressed(); 119 | boolean justPressed(); 120 | boolean justReleased(); 121 | 122 | private: 123 | Adafruit_GFX *_gfx; 124 | int16_t _x, _y; 125 | uint16_t _w, _h; 126 | uint8_t _textsize; 127 | uint16_t _outlinecolor, _fillcolor, _textcolor; 128 | char _label[10]; 129 | 130 | boolean currstate, laststate; 131 | }; 132 | 133 | class GFXcanvas1 : public Adafruit_GFX { 134 | 135 | public: 136 | GFXcanvas1(uint16_t w, uint16_t h); 137 | ~GFXcanvas1(void); 138 | void drawPixel(int16_t x, int16_t y, uint16_t color), 139 | fillScreen(uint16_t color); 140 | uint8_t *getBuffer(void); 141 | private: 142 | uint8_t *buffer; 143 | }; 144 | 145 | class GFXcanvas16 : public Adafruit_GFX { 146 | GFXcanvas16(uint16_t w, uint16_t h); 147 | ~GFXcanvas16(void); 148 | void drawPixel(int16_t x, int16_t y, uint16_t color), 149 | fillScreen(uint16_t color); 150 | uint16_t *getBuffer(void); 151 | private: 152 | uint16_t *buffer; 153 | }; 154 | 155 | #endif // _ADAFRUIT_GFX_H 156 | -------------------------------------------------------------------------------- /lib/Adafruit_GFX_Library/gfxfont.h: -------------------------------------------------------------------------------- 1 | // Font structures for newer Adafruit_GFX (1.1 and later). 2 | // Example fonts are included in 'Fonts' directory. 3 | // To use a font in your Arduino sketch, #include the corresponding .h 4 | // file and pass address of GFXfont struct to setFont(). Pass NULL to 5 | // revert to 'classic' fixed-space bitmap font. 6 | 7 | #ifndef _GFXFONT_H_ 8 | #define _GFXFONT_H_ 9 | 10 | typedef struct { // Data stored PER GLYPH 11 | uint16_t bitmapOffset; // Pointer into GFXfont->bitmap 12 | uint8_t width, height; // Bitmap dimensions in pixels 13 | uint8_t xAdvance; // Distance to advance cursor (x axis) 14 | int8_t xOffset, yOffset; // Dist from cursor pos to UL corner 15 | } GFXglyph; 16 | 17 | typedef struct { // Data stored for FONT AS A WHOLE: 18 | uint8_t *bitmap; // Glyph bitmaps, concatenated 19 | GFXglyph *glyph; // Glyph array 20 | uint8_t first, last; // ASCII extents 21 | uint8_t yAdvance; // Newline distance (y axis) 22 | } GFXfont; 23 | 24 | #endif // _GFXFONT_H_ 25 | -------------------------------------------------------------------------------- /lib/Adafruit_GFX_Library/glcdfont.c: -------------------------------------------------------------------------------- 1 | // This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0. 2 | // See gfxfont.h for newer custom bitmap font info. 3 | 4 | #ifndef FONT5X7_H 5 | #define FONT5X7_H 6 | 7 | #ifdef __AVR__ 8 | #include 9 | #include 10 | #elif defined(ESP8266) 11 | #include 12 | #else 13 | #define PROGMEM 14 | #endif 15 | 16 | // Standard ASCII 5x7 font 17 | 18 | static const unsigned char font[] PROGMEM = { 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 20 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 21 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 22 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 23 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 24 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 25 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 26 | 0x00, 0x18, 0x3C, 0x18, 0x00, 27 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 28 | 0x00, 0x18, 0x24, 0x18, 0x00, 29 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 30 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 31 | 0x26, 0x29, 0x79, 0x29, 0x26, 32 | 0x40, 0x7F, 0x05, 0x05, 0x07, 33 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 34 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 35 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 36 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 37 | 0x14, 0x22, 0x7F, 0x22, 0x14, 38 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 39 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 40 | 0x00, 0x66, 0x89, 0x95, 0x6A, 41 | 0x60, 0x60, 0x60, 0x60, 0x60, 42 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 43 | 0x08, 0x04, 0x7E, 0x04, 0x08, 44 | 0x10, 0x20, 0x7E, 0x20, 0x10, 45 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 46 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 47 | 0x1E, 0x10, 0x10, 0x10, 0x10, 48 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 49 | 0x30, 0x38, 0x3E, 0x38, 0x30, 50 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 52 | 0x00, 0x00, 0x5F, 0x00, 0x00, 53 | 0x00, 0x07, 0x00, 0x07, 0x00, 54 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 55 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 56 | 0x23, 0x13, 0x08, 0x64, 0x62, 57 | 0x36, 0x49, 0x56, 0x20, 0x50, 58 | 0x00, 0x08, 0x07, 0x03, 0x00, 59 | 0x00, 0x1C, 0x22, 0x41, 0x00, 60 | 0x00, 0x41, 0x22, 0x1C, 0x00, 61 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 62 | 0x08, 0x08, 0x3E, 0x08, 0x08, 63 | 0x00, 0x80, 0x70, 0x30, 0x00, 64 | 0x08, 0x08, 0x08, 0x08, 0x08, 65 | 0x00, 0x00, 0x60, 0x60, 0x00, 66 | 0x20, 0x10, 0x08, 0x04, 0x02, 67 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 68 | 0x00, 0x42, 0x7F, 0x40, 0x00, 69 | 0x72, 0x49, 0x49, 0x49, 0x46, 70 | 0x21, 0x41, 0x49, 0x4D, 0x33, 71 | 0x18, 0x14, 0x12, 0x7F, 0x10, 72 | 0x27, 0x45, 0x45, 0x45, 0x39, 73 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 74 | 0x41, 0x21, 0x11, 0x09, 0x07, 75 | 0x36, 0x49, 0x49, 0x49, 0x36, 76 | 0x46, 0x49, 0x49, 0x29, 0x1E, 77 | 0x00, 0x00, 0x14, 0x00, 0x00, 78 | 0x00, 0x40, 0x34, 0x00, 0x00, 79 | 0x00, 0x08, 0x14, 0x22, 0x41, 80 | 0x14, 0x14, 0x14, 0x14, 0x14, 81 | 0x00, 0x41, 0x22, 0x14, 0x08, 82 | 0x02, 0x01, 0x59, 0x09, 0x06, 83 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 84 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 85 | 0x7F, 0x49, 0x49, 0x49, 0x36, 86 | 0x3E, 0x41, 0x41, 0x41, 0x22, 87 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 88 | 0x7F, 0x49, 0x49, 0x49, 0x41, 89 | 0x7F, 0x09, 0x09, 0x09, 0x01, 90 | 0x3E, 0x41, 0x41, 0x51, 0x73, 91 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 92 | 0x00, 0x41, 0x7F, 0x41, 0x00, 93 | 0x20, 0x40, 0x41, 0x3F, 0x01, 94 | 0x7F, 0x08, 0x14, 0x22, 0x41, 95 | 0x7F, 0x40, 0x40, 0x40, 0x40, 96 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 97 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 98 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 99 | 0x7F, 0x09, 0x09, 0x09, 0x06, 100 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 101 | 0x7F, 0x09, 0x19, 0x29, 0x46, 102 | 0x26, 0x49, 0x49, 0x49, 0x32, 103 | 0x03, 0x01, 0x7F, 0x01, 0x03, 104 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 105 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 106 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 107 | 0x63, 0x14, 0x08, 0x14, 0x63, 108 | 0x03, 0x04, 0x78, 0x04, 0x03, 109 | 0x61, 0x59, 0x49, 0x4D, 0x43, 110 | 0x00, 0x7F, 0x41, 0x41, 0x41, 111 | 0x02, 0x04, 0x08, 0x10, 0x20, 112 | 0x00, 0x41, 0x41, 0x41, 0x7F, 113 | 0x04, 0x02, 0x01, 0x02, 0x04, 114 | 0x40, 0x40, 0x40, 0x40, 0x40, 115 | 0x00, 0x03, 0x07, 0x08, 0x00, 116 | 0x20, 0x54, 0x54, 0x78, 0x40, 117 | 0x7F, 0x28, 0x44, 0x44, 0x38, 118 | 0x38, 0x44, 0x44, 0x44, 0x28, 119 | 0x38, 0x44, 0x44, 0x28, 0x7F, 120 | 0x38, 0x54, 0x54, 0x54, 0x18, 121 | 0x00, 0x08, 0x7E, 0x09, 0x02, 122 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 123 | 0x7F, 0x08, 0x04, 0x04, 0x78, 124 | 0x00, 0x44, 0x7D, 0x40, 0x00, 125 | 0x20, 0x40, 0x40, 0x3D, 0x00, 126 | 0x7F, 0x10, 0x28, 0x44, 0x00, 127 | 0x00, 0x41, 0x7F, 0x40, 0x00, 128 | 0x7C, 0x04, 0x78, 0x04, 0x78, 129 | 0x7C, 0x08, 0x04, 0x04, 0x78, 130 | 0x38, 0x44, 0x44, 0x44, 0x38, 131 | 0xFC, 0x18, 0x24, 0x24, 0x18, 132 | 0x18, 0x24, 0x24, 0x18, 0xFC, 133 | 0x7C, 0x08, 0x04, 0x04, 0x08, 134 | 0x48, 0x54, 0x54, 0x54, 0x24, 135 | 0x04, 0x04, 0x3F, 0x44, 0x24, 136 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 137 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 138 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 139 | 0x44, 0x28, 0x10, 0x28, 0x44, 140 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 141 | 0x44, 0x64, 0x54, 0x4C, 0x44, 142 | 0x00, 0x08, 0x36, 0x41, 0x00, 143 | 0x00, 0x00, 0x77, 0x00, 0x00, 144 | 0x00, 0x41, 0x36, 0x08, 0x00, 145 | 0x02, 0x01, 0x02, 0x04, 0x02, 146 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 147 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 148 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 149 | 0x38, 0x54, 0x54, 0x55, 0x59, 150 | 0x21, 0x55, 0x55, 0x79, 0x41, 151 | 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut 152 | 0x21, 0x55, 0x54, 0x78, 0x40, 153 | 0x20, 0x54, 0x55, 0x79, 0x40, 154 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 155 | 0x39, 0x55, 0x55, 0x55, 0x59, 156 | 0x39, 0x54, 0x54, 0x54, 0x59, 157 | 0x39, 0x55, 0x54, 0x54, 0x58, 158 | 0x00, 0x00, 0x45, 0x7C, 0x41, 159 | 0x00, 0x02, 0x45, 0x7D, 0x42, 160 | 0x00, 0x01, 0x45, 0x7C, 0x40, 161 | 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut 162 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 163 | 0x7C, 0x54, 0x55, 0x45, 0x00, 164 | 0x20, 0x54, 0x54, 0x7C, 0x54, 165 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 166 | 0x32, 0x49, 0x49, 0x49, 0x32, 167 | 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut 168 | 0x32, 0x4A, 0x48, 0x48, 0x30, 169 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 170 | 0x3A, 0x42, 0x40, 0x20, 0x78, 171 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 172 | 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut 173 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 174 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 175 | 0x48, 0x7E, 0x49, 0x43, 0x66, 176 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 177 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 178 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 179 | 0x20, 0x54, 0x54, 0x79, 0x41, 180 | 0x00, 0x00, 0x44, 0x7D, 0x41, 181 | 0x30, 0x48, 0x48, 0x4A, 0x32, 182 | 0x38, 0x40, 0x40, 0x22, 0x7A, 183 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 184 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 185 | 0x26, 0x29, 0x29, 0x2F, 0x28, 186 | 0x26, 0x29, 0x29, 0x29, 0x26, 187 | 0x30, 0x48, 0x4D, 0x40, 0x20, 188 | 0x38, 0x08, 0x08, 0x08, 0x08, 189 | 0x08, 0x08, 0x08, 0x08, 0x38, 190 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 191 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 192 | 0x00, 0x00, 0x7B, 0x00, 0x00, 193 | 0x08, 0x14, 0x2A, 0x14, 0x22, 194 | 0x22, 0x14, 0x2A, 0x14, 0x08, 195 | 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code 196 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block 197 | 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block 198 | 0x00, 0x00, 0x00, 0xFF, 0x00, 199 | 0x10, 0x10, 0x10, 0xFF, 0x00, 200 | 0x14, 0x14, 0x14, 0xFF, 0x00, 201 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 202 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 203 | 0x14, 0x14, 0x14, 0xFC, 0x00, 204 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 205 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 206 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 207 | 0x14, 0x14, 0x17, 0x10, 0x1F, 208 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 209 | 0x14, 0x14, 0x14, 0x1F, 0x00, 210 | 0x10, 0x10, 0x10, 0xF0, 0x00, 211 | 0x00, 0x00, 0x00, 0x1F, 0x10, 212 | 0x10, 0x10, 0x10, 0x1F, 0x10, 213 | 0x10, 0x10, 0x10, 0xF0, 0x10, 214 | 0x00, 0x00, 0x00, 0xFF, 0x10, 215 | 0x10, 0x10, 0x10, 0x10, 0x10, 216 | 0x10, 0x10, 0x10, 0xFF, 0x10, 217 | 0x00, 0x00, 0x00, 0xFF, 0x14, 218 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 219 | 0x00, 0x00, 0x1F, 0x10, 0x17, 220 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 221 | 0x14, 0x14, 0x17, 0x10, 0x17, 222 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 223 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 224 | 0x14, 0x14, 0x14, 0x14, 0x14, 225 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 226 | 0x14, 0x14, 0x14, 0x17, 0x14, 227 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 228 | 0x14, 0x14, 0x14, 0xF4, 0x14, 229 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 230 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 231 | 0x00, 0x00, 0x00, 0x1F, 0x14, 232 | 0x00, 0x00, 0x00, 0xFC, 0x14, 233 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 234 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 235 | 0x14, 0x14, 0x14, 0xFF, 0x14, 236 | 0x10, 0x10, 0x10, 0x1F, 0x00, 237 | 0x00, 0x00, 0x00, 0xF0, 0x10, 238 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 239 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 240 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 241 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 242 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 243 | 0x38, 0x44, 0x44, 0x38, 0x44, 244 | 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta 245 | 0x7E, 0x02, 0x02, 0x06, 0x06, 246 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 247 | 0x63, 0x55, 0x49, 0x41, 0x63, 248 | 0x38, 0x44, 0x44, 0x3C, 0x04, 249 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 250 | 0x06, 0x02, 0x7E, 0x02, 0x02, 251 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 252 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 253 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 254 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 255 | 0x30, 0x48, 0x78, 0x48, 0x30, 256 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 257 | 0x3E, 0x49, 0x49, 0x49, 0x00, 258 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 259 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 260 | 0x44, 0x44, 0x5F, 0x44, 0x44, 261 | 0x40, 0x51, 0x4A, 0x44, 0x40, 262 | 0x40, 0x44, 0x4A, 0x51, 0x40, 263 | 0x00, 0x00, 0xFF, 0x01, 0x03, 264 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 265 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 266 | 0x36, 0x12, 0x36, 0x24, 0x36, 267 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 268 | 0x00, 0x00, 0x18, 0x18, 0x00, 269 | 0x00, 0x00, 0x10, 0x10, 0x00, 270 | 0x30, 0x40, 0xFF, 0x01, 0x01, 271 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 272 | 0x00, 0x19, 0x1D, 0x17, 0x12, 273 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 274 | 0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP 275 | }; 276 | #endif // FONT5X7_H 277 | -------------------------------------------------------------------------------- /lib/Adafruit_SSD1306-esp8266-64x48/Adafruit_SSD1306.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a library for our Monochrome OLEDs based on SSD1306 drivers 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/category/63_98 6 | 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface 9 | 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 | BSD license, check license.txt for more information 16 | All text above, and the splash screen below must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #ifdef __AVR__ 20 | #include 21 | #elif defined(ESP8266) 22 | #include 23 | #else 24 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 25 | #endif 26 | 27 | #if !defined(__ARM_ARCH) && !defined(ENERGIA) && !defined(ESP8266) 28 | #include 29 | #endif 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include "Adafruit_GFX.h" 36 | #include "Adafruit_SSD1306.h" 37 | 38 | // the memory buffer for the LCD 39 | 40 | static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = { 41 | 42 | #if (SSD1306_LCDWIDTH == 64 && SSD1306_LCDHEIGHT == 48) 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 45 | 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 48 | 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 49 | 0xFF, 0xFF, 0x7F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 52 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 53 | 0xFF, 0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 54 | 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 56 | 0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87, 0xE7, 0xFF, 0xFF, 57 | 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 58 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 60 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 61 | 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 62 | 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 64 | 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 65 | 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 66 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 67 | #else 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 70 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 71 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 72 | 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 73 | 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 76 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 77 | 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 79 | 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF, 80 | #if (SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH > 96*16) 81 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 82 | 0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 83 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, 84 | 0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 86 | 0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 87 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, 88 | 0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF, 89 | 0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00, 90 | 0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF, 91 | 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF, 92 | 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 93 | 0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F, 94 | 0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 95 | 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03, 96 | 0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 97 | 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, 98 | 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 99 | 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03, 100 | 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 101 | #if (SSD1306_LCDWIDTH == 128 && SSD1306_LCDHEIGHT == 64) 102 | 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F, 103 | 0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF, 104 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00, 105 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 106 | 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 107 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, 108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 110 | 0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, 111 | 0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, 112 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 113 | 0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E, 114 | 0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC, 115 | 0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06, 116 | 0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8, 117 | 0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80, 118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 119 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03, 120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 121 | 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C, 122 | 0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 123 | 0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 124 | 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07, 125 | 0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 126 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 127 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 128 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 129 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 130 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 131 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 132 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 133 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 134 | #endif 135 | #endif 136 | #endif 137 | }; 138 | 139 | #define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; } 140 | 141 | // the most basic function, set a single pixel 142 | void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) { 143 | if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) 144 | return; 145 | 146 | // check rotation, move pixel around if necessary 147 | switch (getRotation()) { 148 | case 1: 149 | ssd1306_swap(x, y); 150 | x = WIDTH - x - 1; 151 | break; 152 | case 2: 153 | x = WIDTH - x - 1; 154 | y = HEIGHT - y - 1; 155 | break; 156 | case 3: 157 | ssd1306_swap(x, y); 158 | y = HEIGHT - y - 1; 159 | break; 160 | } 161 | 162 | // x is which column 163 | switch (color) 164 | { 165 | case WHITE: buffer[x+ (y/8)*SSD1306_LCDWIDTH] |= (1 << (y&7)); break; 166 | case BLACK: buffer[x+ (y/8)*SSD1306_LCDWIDTH] &= ~(1 << (y&7)); break; 167 | case INVERSE: buffer[x+ (y/8)*SSD1306_LCDWIDTH] ^= (1 << (y&7)); break; 168 | } 169 | 170 | } 171 | 172 | Adafruit_SSD1306::Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { 173 | cs = CS; 174 | rst = RST; 175 | dc = DC; 176 | sclk = SCLK; 177 | sid = SID; 178 | hwSPI = false; 179 | } 180 | 181 | // constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset 182 | Adafruit_SSD1306::Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { 183 | dc = DC; 184 | rst = RST; 185 | cs = CS; 186 | hwSPI = true; 187 | } 188 | 189 | // initializer for I2C - we only indicate the reset pin! 190 | Adafruit_SSD1306::Adafruit_SSD1306(int8_t reset) : 191 | Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { 192 | sclk = dc = cs = sid = -1; 193 | rst = reset; 194 | } 195 | 196 | 197 | void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { 198 | _vccstate = vccstate; 199 | _i2caddr = i2caddr; 200 | 201 | // set pin directions 202 | if (sid != -1){ 203 | pinMode(dc, OUTPUT); 204 | pinMode(cs, OUTPUT); 205 | #ifdef HAVE_PORTREG 206 | csport = portOutputRegister(digitalPinToPort(cs)); 207 | cspinmask = digitalPinToBitMask(cs); 208 | dcport = portOutputRegister(digitalPinToPort(dc)); 209 | dcpinmask = digitalPinToBitMask(dc); 210 | #endif 211 | if (!hwSPI){ 212 | // set pins for software-SPI 213 | pinMode(sid, OUTPUT); 214 | pinMode(sclk, OUTPUT); 215 | #ifdef HAVE_PORTREG 216 | clkport = portOutputRegister(digitalPinToPort(sclk)); 217 | clkpinmask = digitalPinToBitMask(sclk); 218 | mosiport = portOutputRegister(digitalPinToPort(sid)); 219 | mosipinmask = digitalPinToBitMask(sid); 220 | #endif 221 | } 222 | if (hwSPI){ 223 | SPI.begin(); 224 | #ifdef SPI_HAS_TRANSACTION 225 | SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0)); 226 | #else 227 | SPI.setClockDivider (4); 228 | #endif 229 | } 230 | } 231 | else 232 | { 233 | // I2C Init 234 | Wire.begin(); 235 | #ifdef __SAM3X8E__ 236 | // Force 400 KHz I2C, rawr! (Uses pins 20, 21 for SDA, SCL) 237 | TWI1->TWI_CWGR = 0; 238 | TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101; 239 | #endif 240 | } 241 | if ((reset) && (rst >= 0)) { 242 | // Setup reset pin direction (used by both SPI and I2C) 243 | pinMode(rst, OUTPUT); 244 | digitalWrite(rst, HIGH); 245 | // VDD (3.3V) goes high at start, lets just chill for a ms 246 | delay(1); 247 | // bring reset low 248 | digitalWrite(rst, LOW); 249 | // wait 10ms 250 | delay(10); 251 | // bring out of reset 252 | digitalWrite(rst, HIGH); 253 | // turn on VCC (9V?) 254 | } 255 | 256 | // Init sequence 257 | ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE 258 | ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5 259 | ssd1306_command(0x80); // the suggested ratio 0x80 260 | 261 | ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8 262 | ssd1306_command(SSD1306_LCDHEIGHT - 1); 263 | 264 | ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3 265 | ssd1306_command(0x0); // no offset 266 | ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 267 | ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D 268 | if (vccstate == SSD1306_EXTERNALVCC) 269 | { ssd1306_command(0x10); } 270 | else 271 | { ssd1306_command(0x14); } 272 | ssd1306_command(SSD1306_MEMORYMODE); // 0x20 horizontal addressing mode 273 | ssd1306_command(0x00); // 0x0 act like ks0108 274 | ssd1306_command(SSD1306_SEGREMAP | 0x1); 275 | ssd1306_command(SSD1306_COMSCANDEC); 276 | 277 | #if defined SSD1306_128_32 278 | ssd1306_command(SSD1306_SETCOMPINS); // 0xDA 279 | ssd1306_command(0x02); 280 | ssd1306_command(SSD1306_SETCONTRAST); // 0x81 281 | ssd1306_command(0x8F); 282 | 283 | #elif defined SSD1306_128_64 284 | ssd1306_command(SSD1306_SETCOMPINS); // 0xDA 285 | ssd1306_command(0x12); 286 | ssd1306_command(SSD1306_SETCONTRAST); // 0x81 287 | if (vccstate == SSD1306_EXTERNALVCC) 288 | { ssd1306_command(0x9F); } 289 | else 290 | { ssd1306_command(0xCF); } 291 | 292 | #elif defined SSD1306_96_16 293 | ssd1306_command(SSD1306_SETCOMPINS); // 0xDA 294 | ssd1306_command(0x2); //ada x12 295 | ssd1306_command(SSD1306_SETCONTRAST); // 0x81 296 | if (vccstate == SSD1306_EXTERNALVCC) 297 | { ssd1306_command(0x10); } 298 | else 299 | { ssd1306_command(0xAF); } 300 | 301 | #elif defined SSD1306_64_48 302 | ssd1306_command(SSD1306_SETCOMPINS); // 0xDA 303 | ssd1306_command(0x12); 304 | ssd1306_command(SSD1306_SETCONTRAST); // 0x81 305 | if (vccstate == SSD1306_EXTERNALVCC) 306 | { ssd1306_command(0x9F); } 307 | else 308 | { ssd1306_command(0xCF); } 309 | 310 | #endif 311 | 312 | ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 313 | if (vccstate == SSD1306_EXTERNALVCC) 314 | { ssd1306_command(0x22); } 315 | else 316 | { ssd1306_command(0xF1); } 317 | ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB 318 | ssd1306_command(0x40); 319 | ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4 320 | ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6 321 | 322 | ssd1306_command(SSD1306_DEACTIVATE_SCROLL); 323 | 324 | ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel 325 | } 326 | 327 | 328 | void Adafruit_SSD1306::invertDisplay(uint8_t i) { 329 | if (i) { 330 | ssd1306_command(SSD1306_INVERTDISPLAY); 331 | } else { 332 | ssd1306_command(SSD1306_NORMALDISPLAY); 333 | } 334 | } 335 | 336 | void Adafruit_SSD1306::ssd1306_command(uint8_t c) { 337 | if (sid != -1) 338 | { 339 | // SPI 340 | #ifdef HAVE_PORTREG 341 | *csport |= cspinmask; 342 | *dcport &= ~dcpinmask; 343 | *csport &= ~cspinmask; 344 | #else 345 | digitalWrite(cs, HIGH); 346 | digitalWrite(dc, LOW); 347 | digitalWrite(cs, LOW); 348 | #endif 349 | fastSPIwrite(c); 350 | #ifdef HAVE_PORTREG 351 | *csport |= cspinmask; 352 | #else 353 | digitalWrite(cs, HIGH); 354 | #endif 355 | } 356 | else 357 | { 358 | // I2C 359 | uint8_t control = 0x00; // Co = 0, D/C = 0 360 | Wire.beginTransmission(_i2caddr); 361 | Wire.write(control); 362 | Wire.write(c); 363 | Wire.endTransmission(); 364 | } 365 | } 366 | 367 | // startscrollright 368 | // Activate a right handed scroll for rows start through stop 369 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 370 | // display.scrollright(0x00, 0x0F) 371 | void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop){ 372 | ssd1306_command(SSD1306_RIGHT_HORIZONTAL_SCROLL); 373 | ssd1306_command(0x00); 374 | ssd1306_command(start); 375 | ssd1306_command(0x00); 376 | ssd1306_command(stop); 377 | ssd1306_command(0x00); 378 | ssd1306_command(0xFF); 379 | ssd1306_command(SSD1306_ACTIVATE_SCROLL); 380 | } 381 | 382 | // startscrollleft 383 | // Activate a right handed scroll for rows start through stop 384 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 385 | // display.scrollright(0x00, 0x0F) 386 | void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop){ 387 | ssd1306_command(SSD1306_LEFT_HORIZONTAL_SCROLL); 388 | ssd1306_command(0x00); 389 | ssd1306_command(start); 390 | ssd1306_command(0x00); 391 | ssd1306_command(stop); 392 | ssd1306_command(0x00); 393 | ssd1306_command(0xFF); 394 | ssd1306_command(SSD1306_ACTIVATE_SCROLL); 395 | } 396 | 397 | // startscrolldiagright 398 | // Activate a diagonal scroll for rows start through stop 399 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 400 | // display.scrollright(0x00, 0x0F) 401 | void Adafruit_SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){ 402 | ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA); 403 | ssd1306_command(0x00); 404 | ssd1306_command(SSD1306_LCDHEIGHT); 405 | ssd1306_command(SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL); 406 | ssd1306_command(0x00); 407 | ssd1306_command(start); 408 | ssd1306_command(0x00); 409 | ssd1306_command(stop); 410 | ssd1306_command(0x01); 411 | ssd1306_command(SSD1306_ACTIVATE_SCROLL); 412 | } 413 | 414 | // startscrolldiagleft 415 | // Activate a diagonal scroll for rows start through stop 416 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 417 | // display.scrollright(0x00, 0x0F) 418 | void Adafruit_SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){ 419 | ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA); 420 | ssd1306_command(0x00); 421 | ssd1306_command(SSD1306_LCDHEIGHT); 422 | ssd1306_command(SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL); 423 | ssd1306_command(0x00); 424 | ssd1306_command(start); 425 | ssd1306_command(0x00); 426 | ssd1306_command(stop); 427 | ssd1306_command(0x01); 428 | ssd1306_command(SSD1306_ACTIVATE_SCROLL); 429 | } 430 | 431 | void Adafruit_SSD1306::stopscroll(void){ 432 | ssd1306_command(SSD1306_DEACTIVATE_SCROLL); 433 | } 434 | 435 | // Dim the display 436 | // dim = true: display is dimmed 437 | // dim = false: display is normal 438 | void Adafruit_SSD1306::dim(boolean dim) { 439 | uint8_t contrast; 440 | 441 | if (dim) { 442 | contrast = 0; // Dimmed display 443 | } else { 444 | if (_vccstate == SSD1306_EXTERNALVCC) { 445 | contrast = 0x9F; 446 | } else { 447 | contrast = 0xCF; 448 | } 449 | } 450 | // the range of contrast to too small to be really useful 451 | // it is useful to dim the display 452 | ssd1306_command(SSD1306_SETCONTRAST); 453 | ssd1306_command(contrast); 454 | } 455 | 456 | void Adafruit_SSD1306::display(void) { 457 | ssd1306_command(SSD1306_COLUMNADDR); 458 | #if SSD1306_LCDWIDTH == 64 && SSD1306_LCDHEIGHT == 48 459 | ssd1306_command(32); 460 | ssd1306_command(32 + SSD1306_LCDWIDTH - 1); 461 | #else 462 | ssd1306_command(0); // Column start address (0 = reset) 463 | ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset) 464 | #endif 465 | 466 | ssd1306_command(SSD1306_PAGEADDR); 467 | ssd1306_command(0); // Page start address (0 = reset) 468 | ssd1306_command((SSD1306_LCDHEIGHT / 8) - 1); // Page end address 469 | /* 470 | #if SSD1306_LCDWIDTH == 128 && SSD1306_LCDHEIGHT == 64 471 | ssd1306_command(7); // Page end address 472 | #elif SSD1306_LCDWIDTH == 64 && SSD1306_LCDHEIGHT == 48 473 | ssd1306_command(5); // Page end address 474 | #elif SSD1306_LCDWIDTH == 128 && SSD1306_LCDHEIGHT == 32 475 | ssd1306_command(3); // Page end address 476 | #elif SSD1306_LCDWIDTH == 96 && SSD1306_LCDHEIGHT == 16 477 | ssd1306_command(1); // Page end address 478 | #endif 479 | */ 480 | 481 | if (sid != -1) 482 | { 483 | // SPI 484 | #ifdef HAVE_PORTREG 485 | *csport |= cspinmask; 486 | *dcport |= dcpinmask; 487 | *csport &= ~cspinmask; 488 | #else 489 | digitalWrite(cs, HIGH); 490 | digitalWrite(dc, HIGH); 491 | digitalWrite(cs, LOW); 492 | #endif 493 | 494 | for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { 495 | fastSPIwrite(buffer[i]); 496 | } 497 | #ifdef HAVE_PORTREG 498 | *csport |= cspinmask; 499 | #else 500 | digitalWrite(cs, HIGH); 501 | #endif 502 | } 503 | else 504 | { 505 | // save I2C bitrate 506 | #ifdef TWBR 507 | uint8_t twbrbackup = TWBR; 508 | TWBR = 12; // upgrade to 400KHz! 509 | #endif 510 | 511 | //Serial.println(TWBR, DEC); 512 | //Serial.println(TWSR & 0x3, DEC); 513 | 514 | // I2C 515 | for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { 516 | // send a bunch of data in one xmission 517 | Wire.beginTransmission(_i2caddr); 518 | WIRE_WRITE(0x40); 519 | for (uint8_t x=0; x<16; x++) { 520 | WIRE_WRITE(buffer[i]); 521 | i++; 522 | } 523 | i--; 524 | Wire.endTransmission(); 525 | } 526 | #ifdef TWBR 527 | TWBR = twbrbackup; 528 | #endif 529 | } 530 | } 531 | 532 | // clear everything 533 | void Adafruit_SSD1306::clearDisplay(void) { 534 | memset(buffer, 0, (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8)); 535 | } 536 | 537 | 538 | inline void Adafruit_SSD1306::fastSPIwrite(uint8_t d) { 539 | 540 | if(hwSPI) { 541 | (void)SPI.transfer(d); 542 | } else { 543 | for(uint8_t bit = 0x80; bit; bit >>= 1) { 544 | #ifdef HAVE_PORTREG 545 | *clkport &= ~clkpinmask; 546 | if(d & bit) *mosiport |= mosipinmask; 547 | else *mosiport &= ~mosipinmask; 548 | *clkport |= clkpinmask; 549 | #else 550 | digitalWrite(sclk, LOW); 551 | if(d & bit) digitalWrite(sid, HIGH); 552 | else digitalWrite(sid, LOW); 553 | digitalWrite(sclk, HIGH); 554 | #endif 555 | } 556 | } 557 | } 558 | 559 | void Adafruit_SSD1306::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { 560 | boolean bSwap = false; 561 | switch(rotation) { 562 | case 0: 563 | // 0 degree rotation, do nothing 564 | break; 565 | case 1: 566 | // 90 degree rotation, swap x & y for rotation, then invert x 567 | bSwap = true; 568 | ssd1306_swap(x, y); 569 | x = WIDTH - x - 1; 570 | break; 571 | case 2: 572 | // 180 degree rotation, invert x and y - then shift y around for height. 573 | x = WIDTH - x - 1; 574 | y = HEIGHT - y - 1; 575 | x -= (w-1); 576 | break; 577 | case 3: 578 | // 270 degree rotation, swap x & y for rotation, then invert y and adjust y for w (not to become h) 579 | bSwap = true; 580 | ssd1306_swap(x, y); 581 | y = HEIGHT - y - 1; 582 | y -= (w-1); 583 | break; 584 | } 585 | 586 | if(bSwap) { 587 | drawFastVLineInternal(x, y, w, color); 588 | } else { 589 | drawFastHLineInternal(x, y, w, color); 590 | } 591 | } 592 | 593 | void Adafruit_SSD1306::drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) { 594 | // Do bounds/limit checks 595 | if(y < 0 || y >= HEIGHT) { return; } 596 | 597 | // make sure we don't try to draw below 0 598 | if(x < 0) { 599 | w += x; 600 | x = 0; 601 | } 602 | 603 | // make sure we don't go off the edge of the display 604 | if( (x + w) > WIDTH) { 605 | w = (WIDTH - x); 606 | } 607 | 608 | // if our width is now negative, punt 609 | if(w <= 0) { return; } 610 | 611 | // set up the pointer for movement through the buffer 612 | register uint8_t *pBuf = buffer; 613 | // adjust the buffer pointer for the current row 614 | pBuf += ((y/8) * SSD1306_LCDWIDTH); 615 | // and offset x columns in 616 | pBuf += x; 617 | 618 | register uint8_t mask = 1 << (y&7); 619 | 620 | switch (color) 621 | { 622 | case WHITE: while(w--) { *pBuf++ |= mask; }; break; 623 | case BLACK: mask = ~mask; while(w--) { *pBuf++ &= mask; }; break; 624 | case INVERSE: while(w--) { *pBuf++ ^= mask; }; break; 625 | } 626 | } 627 | 628 | void Adafruit_SSD1306::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { 629 | bool bSwap = false; 630 | switch(rotation) { 631 | case 0: 632 | break; 633 | case 1: 634 | // 90 degree rotation, swap x & y for rotation, then invert x and adjust x for h (now to become w) 635 | bSwap = true; 636 | ssd1306_swap(x, y); 637 | x = WIDTH - x - 1; 638 | x -= (h-1); 639 | break; 640 | case 2: 641 | // 180 degree rotation, invert x and y - then shift y around for height. 642 | x = WIDTH - x - 1; 643 | y = HEIGHT - y - 1; 644 | y -= (h-1); 645 | break; 646 | case 3: 647 | // 270 degree rotation, swap x & y for rotation, then invert y 648 | bSwap = true; 649 | ssd1306_swap(x, y); 650 | y = HEIGHT - y - 1; 651 | break; 652 | } 653 | 654 | if(bSwap) { 655 | drawFastHLineInternal(x, y, h, color); 656 | } else { 657 | drawFastVLineInternal(x, y, h, color); 658 | } 659 | } 660 | 661 | 662 | void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16_t color) { 663 | 664 | // do nothing if we're off the left or right side of the screen 665 | if(x < 0 || x >= WIDTH) { return; } 666 | 667 | // make sure we don't try to draw below 0 668 | if(__y < 0) { 669 | // __y is negative, this will subtract enough from __h to account for __y being 0 670 | __h += __y; 671 | __y = 0; 672 | 673 | } 674 | 675 | // make sure we don't go past the height of the display 676 | if( (__y + __h) > HEIGHT) { 677 | __h = (HEIGHT - __y); 678 | } 679 | 680 | // if our height is now negative, punt 681 | if(__h <= 0) { 682 | return; 683 | } 684 | 685 | // this display doesn't need ints for coordinates, use local byte registers for faster juggling 686 | register uint8_t y = __y; 687 | register uint8_t h = __h; 688 | 689 | 690 | // set up the pointer for fast movement through the buffer 691 | register uint8_t *pBuf = buffer; 692 | // adjust the buffer pointer for the current row 693 | pBuf += ((y/8) * SSD1306_LCDWIDTH); 694 | // and offset x columns in 695 | pBuf += x; 696 | 697 | // do the first partial byte, if necessary - this requires some masking 698 | register uint8_t mod = (y&7); 699 | if(mod) { 700 | // mask off the high n bits we want to set 701 | mod = 8-mod; 702 | 703 | // note - lookup table results in a nearly 10% performance improvement in fill* functions 704 | // register uint8_t mask = ~(0xFF >> (mod)); 705 | static uint8_t premask[8] = {0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; 706 | register uint8_t mask = premask[mod]; 707 | 708 | // adjust the mask if we're not going to reach the end of this byte 709 | if( h < mod) { 710 | mask &= (0xFF >> (mod-h)); 711 | } 712 | 713 | switch (color) 714 | { 715 | case WHITE: *pBuf |= mask; break; 716 | case BLACK: *pBuf &= ~mask; break; 717 | case INVERSE: *pBuf ^= mask; break; 718 | } 719 | 720 | // fast exit if we're done here! 721 | if(h= 8) { 731 | if (color == INVERSE) { // separate copy of the code so we don't impact performance of the black/white write version with an extra comparison per loop 732 | do { 733 | *pBuf=~(*pBuf); 734 | 735 | // adjust the buffer forward 8 rows worth of data 736 | pBuf += SSD1306_LCDWIDTH; 737 | 738 | // adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now) 739 | h -= 8; 740 | } while(h >= 8); 741 | } 742 | else { 743 | // store a local value to work with 744 | register uint8_t val = (color == WHITE) ? 255 : 0; 745 | 746 | do { 747 | // write our value in 748 | *pBuf = val; 749 | 750 | // adjust the buffer forward 8 rows worth of data 751 | pBuf += SSD1306_LCDWIDTH; 752 | 753 | // adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now) 754 | h -= 8; 755 | } while(h >= 8); 756 | } 757 | } 758 | 759 | // now do the final partial byte, if necessary 760 | if(h) { 761 | mod = h & 7; 762 | // this time we want to mask the low bits of the byte, vs the high bits we did above 763 | // register uint8_t mask = (1 << mod) - 1; 764 | // note - lookup table results in a nearly 10% performance improvement in fill* functions 765 | static uint8_t postmask[8] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F }; 766 | register uint8_t mask = postmask[mod]; 767 | switch (color) 768 | { 769 | case WHITE: *pBuf |= mask; break; 770 | case BLACK: *pBuf &= ~mask; break; 771 | case INVERSE: *pBuf ^= mask; break; 772 | } 773 | } 774 | } 775 | -------------------------------------------------------------------------------- /lib/Adafruit_SSD1306-esp8266-64x48/Adafruit_SSD1306.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a library for our Monochrome OLEDs based on SSD1306 drivers 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/category/63_98 6 | 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface 9 | 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 | BSD license, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | #ifndef _Adafruit_SSD1306_H_ 19 | #define _Adafruit_SSD1306_H_ 20 | 21 | #if ARDUINO >= 100 22 | #include "Arduino.h" 23 | #define WIRE_WRITE Wire.write 24 | #else 25 | #include "WProgram.h" 26 | #define WIRE_WRITE Wire.send 27 | #endif 28 | 29 | #if defined(__SAM3X8E__) 30 | typedef volatile RwReg PortReg; 31 | typedef uint32_t PortMask; 32 | #define HAVE_PORTREG 33 | #elif defined(ARDUINO_ARCH_SAMD) 34 | // not supported 35 | #elif defined(ESP8266) || defined(ARDUINO_STM32_FEATHER) 36 | typedef volatile uint32_t PortReg; 37 | typedef uint32_t PortMask; 38 | #else 39 | typedef volatile uint8_t PortReg; 40 | typedef uint8_t PortMask; 41 | #define HAVE_PORTREG 42 | #endif 43 | 44 | #include 45 | #include 46 | 47 | #define BLACK 0 48 | #define WHITE 1 49 | #define INVERSE 2 50 | 51 | #define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D 52 | // Address for 128x32 is 0x3C 53 | // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded) 54 | 55 | /*========================================================================= 56 | SSD1306 Displays 57 | ----------------------------------------------------------------------- 58 | The driver is used in multiple displays (128x64, 128x32, etc.). 59 | Select the appropriate display below to create an appropriately 60 | sized framebuffer, etc. 61 | 62 | SSD1306_128_64 128x64 pixel display 63 | 64 | SSD1306_128_32 128x32 pixel display 65 | 66 | SSD1306_96_16 67 | 68 | -----------------------------------------------------------------------*/ 69 | #define SSD1306_64_48 70 | // #define SSD1306_128_64 71 | // #define SSD1306_128_32 72 | // #define SSD1306_96_16 73 | /*=========================================================================*/ 74 | 75 | #if defined SSD1306_128_64 && defined SSD1306_128_32 76 | #error "Only one SSD1306 display can be specified at once in Adafruit_SSD1306.h" 77 | #endif 78 | #if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 && !defined SSD1306_64_48 79 | #error "At least one SSD1306 display must be specified in Adafruit_SSD1306.h" 80 | #endif 81 | 82 | #if defined SSD1306_128_64 83 | #define SSD1306_LCDWIDTH 128 84 | #define SSD1306_LCDHEIGHT 64 85 | #elif defined SSD1306_128_32 86 | #define SSD1306_LCDWIDTH 128 87 | #define SSD1306_LCDHEIGHT 32 88 | #elif defined SSD1306_96_16 89 | #define SSD1306_LCDWIDTH 96 90 | #define SSD1306_LCDHEIGHT 16 91 | #elif defined SSD1306_64_48 92 | #define SSD1306_LCDWIDTH 64 93 | #define SSD1306_LCDHEIGHT 48 94 | #endif 95 | 96 | #define SSD1306_SETCONTRAST 0x81 97 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 98 | #define SSD1306_DISPLAYALLON 0xA5 99 | #define SSD1306_NORMALDISPLAY 0xA6 100 | #define SSD1306_INVERTDISPLAY 0xA7 101 | #define SSD1306_DISPLAYOFF 0xAE 102 | #define SSD1306_DISPLAYON 0xAF 103 | 104 | #define SSD1306_SETDISPLAYOFFSET 0xD3 105 | #define SSD1306_SETCOMPINS 0xDA 106 | 107 | #define SSD1306_SETVCOMDETECT 0xDB 108 | 109 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 110 | #define SSD1306_SETPRECHARGE 0xD9 111 | 112 | #define SSD1306_SETMULTIPLEX 0xA8 113 | 114 | #define SSD1306_SETLOWCOLUMN 0x00 115 | #define SSD1306_SETHIGHCOLUMN 0x10 116 | 117 | #define SSD1306_SETSTARTLINE 0x40 118 | 119 | #define SSD1306_MEMORYMODE 0x20 120 | #define SSD1306_COLUMNADDR 0x21 121 | #define SSD1306_PAGEADDR 0x22 122 | 123 | #define SSD1306_COMSCANINC 0xC0 124 | #define SSD1306_COMSCANDEC 0xC8 125 | 126 | #define SSD1306_SEGREMAP 0xA0 127 | 128 | #define SSD1306_CHARGEPUMP 0x8D 129 | 130 | #define SSD1306_EXTERNALVCC 0x1 131 | #define SSD1306_SWITCHCAPVCC 0x2 132 | 133 | // Scrolling #defines 134 | #define SSD1306_ACTIVATE_SCROLL 0x2F 135 | #define SSD1306_DEACTIVATE_SCROLL 0x2E 136 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 137 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 138 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 139 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 140 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A 141 | 142 | class Adafruit_SSD1306 : public Adafruit_GFX { 143 | public: 144 | Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS); 145 | Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS); 146 | Adafruit_SSD1306(int8_t RST = -1); 147 | 148 | void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset=true); 149 | void ssd1306_command(uint8_t c); 150 | 151 | void clearDisplay(void); 152 | void invertDisplay(uint8_t i); 153 | void display(); 154 | 155 | void startscrollright(uint8_t start, uint8_t stop); 156 | void startscrollleft(uint8_t start, uint8_t stop); 157 | 158 | void startscrolldiagright(uint8_t start, uint8_t stop); 159 | void startscrolldiagleft(uint8_t start, uint8_t stop); 160 | void stopscroll(void); 161 | 162 | void dim(boolean dim); 163 | 164 | void drawPixel(int16_t x, int16_t y, uint16_t color); 165 | 166 | virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 167 | virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 168 | 169 | private: 170 | int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs; 171 | void fastSPIwrite(uint8_t c); 172 | 173 | boolean hwSPI; 174 | #ifdef HAVE_PORTREG 175 | PortReg *mosiport, *clkport, *csport, *dcport; 176 | PortMask mosipinmask, clkpinmask, cspinmask, dcpinmask; 177 | #endif 178 | 179 | inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline)); 180 | inline void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) __attribute__((always_inline)); 181 | 182 | }; 183 | 184 | #endif /* _Adafruit_SSD1306_H_ */ 185 | -------------------------------------------------------------------------------- /lib/Adafruit_SSD1306-esp8266-64x48/README.md: -------------------------------------------------------------------------------- 1 | # Adafruit_SSD1306 2 | 3 | 4 | ## Compatibility 5 | 6 | MCU | Tested Works | Doesn't Work | Not Tested | Notes 7 | ----------------- | :----------: | :----------: | :---------: | ----- 8 | Atmega328 @ 16MHz | X | | | 9 | Atmega328 @ 12MHz | X | | | 10 | Atmega32u4 @ 16MHz | X | | | 11 | Atmega32u4 @ 8MHz | X | | | 12 | ESP8266 | X | | | change OLED_RESET to different pin if using default I2C pins D4/D5. 13 | Atmega2560 @ 16MHz | X | | | 14 | ATSAM3X8E | X | | | 15 | ATSAM21D | X | | | 16 | ATtiny85 @ 16MHz | | X | | 17 | ATtiny85 @ 8MHz | | X | | 18 | 19 | * ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini 20 | * ATmega328 @ 12MHz : Adafruit Pro Trinket 3V 21 | * ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0 22 | * ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro 23 | * ESP8266 : Adafruit Huzzah 24 | * ATmega2560 @ 16MHz : Arduino Mega 25 | * ATSAM3X8E : Arduino Due 26 | * ATSAM21D : Arduino Zero, M0 Pro 27 | * ATtiny85 @ 16MHz : Adafruit Trinket 5V 28 | * ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V 29 | 30 | 31 | -------------------------------------------------------------------------------- /lib/Adafruit_SSD1306-esp8266-64x48/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for our Monochrome OLEDs based on SSD1306 drivers 2 | 3 | Pick one up today in the adafruit shop! 4 | ------> http://www.adafruit.com/category/63_98 5 | 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | Scrolling code contributed by Michael Gregg 15 | BSD license, check license.txt for more information 16 | All text above must be included in any redistribution 17 | 18 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1306. Check that the Adafruit_SSD1306 folder contains Adafruit_SSD1306.cpp and Adafruit_SSD1306.h 19 | 20 | Place the Adafruit_SSD1306 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. 21 | 22 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from 23 | https://github.com/adafruit/Adafruit-GFX-Library 24 | and download/install that library as well -------------------------------------------------------------------------------- /lib/Adafruit_SSD1306-esp8266-64x48/examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is an example for our Monochrome OLEDs based on SSD1306 drivers 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/category/63_98 6 | 7 | This example is for a 128x32 size display using I2C to communicate 8 | 3 pins are required to interface (2 I2C and one reset) 9 | 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 | BSD license, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define OLED_RESET 4 25 | Adafruit_SSD1306 display(OLED_RESET); 26 | 27 | #define NUMFLAKES 10 28 | #define XPOS 0 29 | #define YPOS 1 30 | #define DELTAY 2 31 | 32 | 33 | #define LOGO16_GLCD_HEIGHT 16 34 | #define LOGO16_GLCD_WIDTH 16 35 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 36 | { B00000000, B11000000, 37 | B00000001, B11000000, 38 | B00000001, B11000000, 39 | B00000011, B11100000, 40 | B11110011, B11100000, 41 | B11111110, B11111000, 42 | B01111110, B11111111, 43 | B00110011, B10011111, 44 | B00011111, B11111100, 45 | B00001101, B01110000, 46 | B00011011, B10100000, 47 | B00111111, B11100000, 48 | B00111111, B11110000, 49 | B01111100, B11110000, 50 | B01110000, B01110000, 51 | B00000000, B00110000 }; 52 | 53 | #if (SSD1306_LCDHEIGHT != 32) 54 | #error("Height incorrect, please fix Adafruit_SSD1306.h!"); 55 | #endif 56 | 57 | void setup() { 58 | Serial.begin(9600); 59 | 60 | // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) 61 | display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) 62 | // init done 63 | 64 | // Show image buffer on the display hardware. 65 | // Since the buffer is intialized with an Adafruit splashscreen 66 | // internally, this will display the splashscreen. 67 | display.display(); 68 | delay(2000); 69 | 70 | // Clear the buffer. 71 | display.clearDisplay(); 72 | 73 | // draw a single pixel 74 | display.drawPixel(10, 10, WHITE); 75 | // Show the display buffer on the hardware. 76 | // NOTE: You _must_ call display after making any drawing commands 77 | // to make them visible on the display hardware! 78 | display.display(); 79 | delay(2000); 80 | display.clearDisplay(); 81 | 82 | // draw many lines 83 | testdrawline(); 84 | display.display(); 85 | delay(2000); 86 | display.clearDisplay(); 87 | 88 | // draw rectangles 89 | testdrawrect(); 90 | display.display(); 91 | delay(2000); 92 | display.clearDisplay(); 93 | 94 | // draw multiple rectangles 95 | testfillrect(); 96 | display.display(); 97 | delay(2000); 98 | display.clearDisplay(); 99 | 100 | // draw mulitple circles 101 | testdrawcircle(); 102 | display.display(); 103 | delay(2000); 104 | display.clearDisplay(); 105 | 106 | // draw a white circle, 10 pixel radius 107 | display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); 108 | display.display(); 109 | delay(2000); 110 | display.clearDisplay(); 111 | 112 | testdrawroundrect(); 113 | delay(2000); 114 | display.clearDisplay(); 115 | 116 | testfillroundrect(); 117 | delay(2000); 118 | display.clearDisplay(); 119 | 120 | testdrawtriangle(); 121 | delay(2000); 122 | display.clearDisplay(); 123 | 124 | testfilltriangle(); 125 | delay(2000); 126 | display.clearDisplay(); 127 | 128 | // draw the first ~12 characters in the font 129 | testdrawchar(); 130 | display.display(); 131 | delay(2000); 132 | display.clearDisplay(); 133 | 134 | // draw scrolling text 135 | testscrolltext(); 136 | delay(2000); 137 | display.clearDisplay(); 138 | 139 | // text display tests 140 | display.setTextSize(1); 141 | display.setTextColor(WHITE); 142 | display.setCursor(0,0); 143 | display.println("Hello, world!"); 144 | display.setTextColor(BLACK, WHITE); // 'inverted' text 145 | display.println(3.141592); 146 | display.setTextSize(2); 147 | display.setTextColor(WHITE); 148 | display.print("0x"); display.println(0xDEADBEEF, HEX); 149 | display.display(); 150 | delay(2000); 151 | display.clearDisplay(); 152 | 153 | // miniature bitmap display 154 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 155 | display.display(); 156 | delay(1); 157 | 158 | // invert the display 159 | display.invertDisplay(true); 160 | delay(1000); 161 | display.invertDisplay(false); 162 | delay(1000); 163 | display.clearDisplay(); 164 | 165 | // draw a bitmap icon and 'animate' movement 166 | testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); 167 | } 168 | 169 | 170 | void loop() { 171 | 172 | } 173 | 174 | 175 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 176 | uint8_t icons[NUMFLAKES][3]; 177 | 178 | // initialize 179 | for (uint8_t f=0; f< NUMFLAKES; f++) { 180 | icons[f][XPOS] = random(display.width()); 181 | icons[f][YPOS] = 0; 182 | icons[f][DELTAY] = random(5) + 1; 183 | 184 | Serial.print("x: "); 185 | Serial.print(icons[f][XPOS], DEC); 186 | Serial.print(" y: "); 187 | Serial.print(icons[f][YPOS], DEC); 188 | Serial.print(" dy: "); 189 | Serial.println(icons[f][DELTAY], DEC); 190 | } 191 | 192 | while (1) { 193 | // draw each icon 194 | for (uint8_t f=0; f< NUMFLAKES; f++) { 195 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE); 196 | } 197 | display.display(); 198 | delay(200); 199 | 200 | // then erase it + move it 201 | for (uint8_t f=0; f< NUMFLAKES; f++) { 202 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); 203 | // move it 204 | icons[f][YPOS] += icons[f][DELTAY]; 205 | // if its gone, reinit 206 | if (icons[f][YPOS] > display.height()) { 207 | icons[f][XPOS] = random(display.width()); 208 | icons[f][YPOS] = 0; 209 | icons[f][DELTAY] = random(5) + 1; 210 | } 211 | } 212 | } 213 | } 214 | 215 | 216 | void testdrawchar(void) { 217 | display.setTextSize(1); 218 | display.setTextColor(WHITE); 219 | display.setCursor(0,0); 220 | 221 | for (uint8_t i=0; i < 168; i++) { 222 | if (i == '\n') continue; 223 | display.write(i); 224 | if ((i > 0) && (i % 21 == 0)) 225 | display.println(); 226 | } 227 | display.display(); 228 | delay(1); 229 | } 230 | 231 | void testdrawcircle(void) { 232 | for (int16_t i=0; i0; i-=5) { 263 | display.fillTriangle(display.width()/2, display.height()/2-i, 264 | display.width()/2-i, display.height()/2+i, 265 | display.width()/2+i, display.height()/2+i, WHITE); 266 | if (color == WHITE) color = BLACK; 267 | else color = WHITE; 268 | display.display(); 269 | delay(1); 270 | } 271 | } 272 | 273 | void testdrawroundrect(void) { 274 | for (int16_t i=0; i=0; i-=4) { 320 | display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); 321 | display.display(); 322 | delay(1); 323 | } 324 | delay(250); 325 | 326 | display.clearDisplay(); 327 | for (int16_t i=display.width()-1; i>=0; i-=4) { 328 | display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); 329 | display.display(); 330 | delay(1); 331 | } 332 | for (int16_t i=display.height()-1; i>=0; i-=4) { 333 | display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); 334 | display.display(); 335 | delay(1); 336 | } 337 | delay(250); 338 | 339 | display.clearDisplay(); 340 | for (int16_t i=0; i http://www.adafruit.com/category/63_98 6 | 7 | This example is for a 128x32 size display using SPI to communicate 8 | 4 or 5 pins are required to interface 9 | 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 | BSD license, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | // If using software SPI (the default case): 25 | #define OLED_MOSI 9 26 | #define OLED_CLK 10 27 | #define OLED_DC 11 28 | #define OLED_CS 12 29 | #define OLED_RESET 13 30 | Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 31 | 32 | /* Uncomment this block to use hardware SPI 33 | #define OLED_DC 6 34 | #define OLED_CS 7 35 | #define OLED_RESET 8 36 | Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS); 37 | */ 38 | 39 | #define NUMFLAKES 10 40 | #define XPOS 0 41 | #define YPOS 1 42 | #define DELTAY 2 43 | 44 | #define LOGO16_GLCD_HEIGHT 16 45 | #define LOGO16_GLCD_WIDTH 16 46 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 47 | { B00000000, B11000000, 48 | B00000001, B11000000, 49 | B00000001, B11000000, 50 | B00000011, B11100000, 51 | B11110011, B11100000, 52 | B11111110, B11111000, 53 | B01111110, B11111111, 54 | B00110011, B10011111, 55 | B00011111, B11111100, 56 | B00001101, B01110000, 57 | B00011011, B10100000, 58 | B00111111, B11100000, 59 | B00111111, B11110000, 60 | B01111100, B11110000, 61 | B01110000, B01110000, 62 | B00000000, B00110000 }; 63 | 64 | #if (SSD1306_LCDHEIGHT != 32) 65 | #error("Height incorrect, please fix Adafruit_SSD1306.h!"); 66 | #endif 67 | 68 | void setup() { 69 | Serial.begin(9600); 70 | 71 | // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) 72 | display.begin(SSD1306_SWITCHCAPVCC); 73 | // init done 74 | 75 | // Show image buffer on the display hardware. 76 | // Since the buffer is intialized with an Adafruit splashscreen 77 | // internally, this will display the splashscreen. 78 | display.display(); 79 | delay(2000); 80 | 81 | // Clear the buffer. 82 | display.clearDisplay(); 83 | 84 | // draw a single pixel 85 | display.drawPixel(10, 10, WHITE); 86 | // Show the display buffer on the hardware. 87 | // NOTE: You _must_ call display after making any drawing commands 88 | // to make them visible on the display hardware! 89 | display.display(); 90 | delay(2000); 91 | display.clearDisplay(); 92 | 93 | // draw many lines 94 | testdrawline(); 95 | display.display(); 96 | delay(2000); 97 | display.clearDisplay(); 98 | 99 | // draw rectangles 100 | testdrawrect(); 101 | display.display(); 102 | delay(2000); 103 | display.clearDisplay(); 104 | 105 | // draw multiple rectangles 106 | testfillrect(); 107 | display.display(); 108 | delay(2000); 109 | display.clearDisplay(); 110 | 111 | // draw mulitple circles 112 | testdrawcircle(); 113 | display.display(); 114 | delay(2000); 115 | display.clearDisplay(); 116 | 117 | // draw a white circle, 10 pixel radius 118 | display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); 119 | display.display(); 120 | delay(2000); 121 | display.clearDisplay(); 122 | 123 | testdrawroundrect(); 124 | delay(2000); 125 | display.clearDisplay(); 126 | 127 | testfillroundrect(); 128 | delay(2000); 129 | display.clearDisplay(); 130 | 131 | testdrawtriangle(); 132 | delay(2000); 133 | display.clearDisplay(); 134 | 135 | testfilltriangle(); 136 | delay(2000); 137 | display.clearDisplay(); 138 | 139 | // draw the first ~12 characters in the font 140 | testdrawchar(); 141 | display.display(); 142 | delay(2000); 143 | display.clearDisplay(); 144 | 145 | // draw scrolling text 146 | testscrolltext(); 147 | delay(2000); 148 | display.clearDisplay(); 149 | 150 | // text display tests 151 | display.setTextSize(1); 152 | display.setTextColor(WHITE); 153 | display.setCursor(0,0); 154 | display.println("Hello, world!"); 155 | display.setTextColor(BLACK, WHITE); // 'inverted' text 156 | display.println(3.141592); 157 | display.setTextSize(2); 158 | display.setTextColor(WHITE); 159 | display.print("0x"); display.println(0xDEADBEEF, HEX); 160 | display.display(); 161 | delay(2000); 162 | display.clearDisplay(); 163 | 164 | // miniature bitmap display 165 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 166 | display.display(); 167 | 168 | // invert the display 169 | display.invertDisplay(true); 170 | delay(1000); 171 | display.invertDisplay(false); 172 | delay(1000); 173 | display.clearDisplay(); 174 | 175 | // draw a bitmap icon and 'animate' movement 176 | testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); 177 | } 178 | 179 | 180 | void loop() { 181 | 182 | } 183 | 184 | 185 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 186 | uint8_t icons[NUMFLAKES][3]; 187 | 188 | // initialize 189 | for (uint8_t f=0; f< NUMFLAKES; f++) { 190 | icons[f][XPOS] = random(display.width()); 191 | icons[f][YPOS] = 0; 192 | icons[f][DELTAY] = random(5) + 1; 193 | 194 | Serial.print("x: "); 195 | Serial.print(icons[f][XPOS], DEC); 196 | Serial.print(" y: "); 197 | Serial.print(icons[f][YPOS], DEC); 198 | Serial.print(" dy: "); 199 | Serial.println(icons[f][DELTAY], DEC); 200 | } 201 | 202 | while (1) { 203 | // draw each icon 204 | for (uint8_t f=0; f< NUMFLAKES; f++) { 205 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE); 206 | } 207 | display.display(); 208 | delay(200); 209 | 210 | // then erase it + move it 211 | for (uint8_t f=0; f< NUMFLAKES; f++) { 212 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); 213 | // move it 214 | icons[f][YPOS] += icons[f][DELTAY]; 215 | // if its gone, reinit 216 | if (icons[f][YPOS] > display.height()) { 217 | icons[f][XPOS] = random(display.width()); 218 | icons[f][YPOS] = 0; 219 | icons[f][DELTAY] = random(5) + 1; 220 | } 221 | } 222 | } 223 | } 224 | 225 | 226 | void testdrawchar(void) { 227 | display.setTextSize(1); 228 | display.setTextColor(WHITE); 229 | display.setCursor(0,0); 230 | 231 | for (uint8_t i=0; i < 168; i++) { 232 | if (i == '\n') continue; 233 | display.write(i); 234 | if ((i > 0) && (i % 21 == 0)) 235 | display.println(); 236 | } 237 | display.display(); 238 | } 239 | 240 | void testdrawcircle(void) { 241 | for (int16_t i=0; i0; i-=5) { 269 | display.fillTriangle(display.width()/2, display.height()/2-i, 270 | display.width()/2-i, display.height()/2+i, 271 | display.width()/2+i, display.height()/2+i, WHITE); 272 | if (color == WHITE) color = BLACK; 273 | else color = WHITE; 274 | display.display(); 275 | } 276 | } 277 | 278 | void testdrawroundrect(void) { 279 | for (int16_t i=0; i=0; i-=4) { 319 | display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); 320 | display.display(); 321 | } 322 | delay(250); 323 | 324 | display.clearDisplay(); 325 | for (int16_t i=display.width()-1; i>=0; i-=4) { 326 | display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); 327 | display.display(); 328 | } 329 | for (int16_t i=display.height()-1; i>=0; i-=4) { 330 | display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); 331 | display.display(); 332 | } 333 | delay(250); 334 | 335 | display.clearDisplay(); 336 | for (int16_t i=0; i http://www.adafruit.com/category/63_98 6 | 7 | This example is for a 128x64 size display using I2C to communicate 8 | 3 pins are required to interface (2 I2C and one reset) 9 | 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 | BSD license, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define OLED_RESET 4 25 | Adafruit_SSD1306 display(OLED_RESET); 26 | 27 | #define NUMFLAKES 10 28 | #define XPOS 0 29 | #define YPOS 1 30 | #define DELTAY 2 31 | 32 | 33 | #define LOGO16_GLCD_HEIGHT 16 34 | #define LOGO16_GLCD_WIDTH 16 35 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 36 | { B00000000, B11000000, 37 | B00000001, B11000000, 38 | B00000001, B11000000, 39 | B00000011, B11100000, 40 | B11110011, B11100000, 41 | B11111110, B11111000, 42 | B01111110, B11111111, 43 | B00110011, B10011111, 44 | B00011111, B11111100, 45 | B00001101, B01110000, 46 | B00011011, B10100000, 47 | B00111111, B11100000, 48 | B00111111, B11110000, 49 | B01111100, B11110000, 50 | B01110000, B01110000, 51 | B00000000, B00110000 }; 52 | 53 | #if (SSD1306_LCDHEIGHT != 64) 54 | #error("Height incorrect, please fix Adafruit_SSD1306.h!"); 55 | #endif 56 | 57 | void setup() { 58 | Serial.begin(9600); 59 | 60 | // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) 61 | display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64) 62 | // init done 63 | 64 | // Show image buffer on the display hardware. 65 | // Since the buffer is intialized with an Adafruit splashscreen 66 | // internally, this will display the splashscreen. 67 | display.display(); 68 | delay(2000); 69 | 70 | // Clear the buffer. 71 | display.clearDisplay(); 72 | 73 | // draw a single pixel 74 | display.drawPixel(10, 10, WHITE); 75 | // Show the display buffer on the hardware. 76 | // NOTE: You _must_ call display after making any drawing commands 77 | // to make them visible on the display hardware! 78 | display.display(); 79 | delay(2000); 80 | display.clearDisplay(); 81 | 82 | // draw many lines 83 | testdrawline(); 84 | display.display(); 85 | delay(2000); 86 | display.clearDisplay(); 87 | 88 | // draw rectangles 89 | testdrawrect(); 90 | display.display(); 91 | delay(2000); 92 | display.clearDisplay(); 93 | 94 | // draw multiple rectangles 95 | testfillrect(); 96 | display.display(); 97 | delay(2000); 98 | display.clearDisplay(); 99 | 100 | // draw mulitple circles 101 | testdrawcircle(); 102 | display.display(); 103 | delay(2000); 104 | display.clearDisplay(); 105 | 106 | // draw a white circle, 10 pixel radius 107 | display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); 108 | display.display(); 109 | delay(2000); 110 | display.clearDisplay(); 111 | 112 | testdrawroundrect(); 113 | delay(2000); 114 | display.clearDisplay(); 115 | 116 | testfillroundrect(); 117 | delay(2000); 118 | display.clearDisplay(); 119 | 120 | testdrawtriangle(); 121 | delay(2000); 122 | display.clearDisplay(); 123 | 124 | testfilltriangle(); 125 | delay(2000); 126 | display.clearDisplay(); 127 | 128 | // draw the first ~12 characters in the font 129 | testdrawchar(); 130 | display.display(); 131 | delay(2000); 132 | display.clearDisplay(); 133 | 134 | // draw scrolling text 135 | testscrolltext(); 136 | delay(2000); 137 | display.clearDisplay(); 138 | 139 | // text display tests 140 | display.setTextSize(1); 141 | display.setTextColor(WHITE); 142 | display.setCursor(0,0); 143 | display.println("Hello, world!"); 144 | display.setTextColor(BLACK, WHITE); // 'inverted' text 145 | display.println(3.141592); 146 | display.setTextSize(2); 147 | display.setTextColor(WHITE); 148 | display.print("0x"); display.println(0xDEADBEEF, HEX); 149 | display.display(); 150 | delay(2000); 151 | display.clearDisplay(); 152 | 153 | // miniature bitmap display 154 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 155 | display.display(); 156 | delay(1); 157 | 158 | // invert the display 159 | display.invertDisplay(true); 160 | delay(1000); 161 | display.invertDisplay(false); 162 | delay(1000); 163 | display.clearDisplay(); 164 | 165 | // draw a bitmap icon and 'animate' movement 166 | testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); 167 | } 168 | 169 | 170 | void loop() { 171 | 172 | } 173 | 174 | 175 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 176 | uint8_t icons[NUMFLAKES][3]; 177 | 178 | // initialize 179 | for (uint8_t f=0; f< NUMFLAKES; f++) { 180 | icons[f][XPOS] = random(display.width()); 181 | icons[f][YPOS] = 0; 182 | icons[f][DELTAY] = random(5) + 1; 183 | 184 | Serial.print("x: "); 185 | Serial.print(icons[f][XPOS], DEC); 186 | Serial.print(" y: "); 187 | Serial.print(icons[f][YPOS], DEC); 188 | Serial.print(" dy: "); 189 | Serial.println(icons[f][DELTAY], DEC); 190 | } 191 | 192 | while (1) { 193 | // draw each icon 194 | for (uint8_t f=0; f< NUMFLAKES; f++) { 195 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE); 196 | } 197 | display.display(); 198 | delay(200); 199 | 200 | // then erase it + move it 201 | for (uint8_t f=0; f< NUMFLAKES; f++) { 202 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); 203 | // move it 204 | icons[f][YPOS] += icons[f][DELTAY]; 205 | // if its gone, reinit 206 | if (icons[f][YPOS] > display.height()) { 207 | icons[f][XPOS] = random(display.width()); 208 | icons[f][YPOS] = 0; 209 | icons[f][DELTAY] = random(5) + 1; 210 | } 211 | } 212 | } 213 | } 214 | 215 | 216 | void testdrawchar(void) { 217 | display.setTextSize(1); 218 | display.setTextColor(WHITE); 219 | display.setCursor(0,0); 220 | 221 | for (uint8_t i=0; i < 168; i++) { 222 | if (i == '\n') continue; 223 | display.write(i); 224 | if ((i > 0) && (i % 21 == 0)) 225 | display.println(); 226 | } 227 | display.display(); 228 | delay(1); 229 | } 230 | 231 | void testdrawcircle(void) { 232 | for (int16_t i=0; i0; i-=5) { 263 | display.fillTriangle(display.width()/2, display.height()/2-i, 264 | display.width()/2-i, display.height()/2+i, 265 | display.width()/2+i, display.height()/2+i, WHITE); 266 | if (color == WHITE) color = BLACK; 267 | else color = WHITE; 268 | display.display(); 269 | delay(1); 270 | } 271 | } 272 | 273 | void testdrawroundrect(void) { 274 | for (int16_t i=0; i=0; i-=4) { 320 | display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); 321 | display.display(); 322 | delay(1); 323 | } 324 | delay(250); 325 | 326 | display.clearDisplay(); 327 | for (int16_t i=display.width()-1; i>=0; i-=4) { 328 | display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); 329 | display.display(); 330 | delay(1); 331 | } 332 | for (int16_t i=display.height()-1; i>=0; i-=4) { 333 | display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); 334 | display.display(); 335 | delay(1); 336 | } 337 | delay(250); 338 | 339 | display.clearDisplay(); 340 | for (int16_t i=0; i http://www.adafruit.com/category/63_98 6 | 7 | This example is for a 128x64 size display using SPI to communicate 8 | 4 or 5 pins are required to interface 9 | 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 | BSD license, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | // If using software SPI (the default case): 25 | #define OLED_MOSI 9 26 | #define OLED_CLK 10 27 | #define OLED_DC 11 28 | #define OLED_CS 12 29 | #define OLED_RESET 13 30 | Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 31 | 32 | /* Uncomment this block to use hardware SPI 33 | #define OLED_DC 6 34 | #define OLED_CS 7 35 | #define OLED_RESET 8 36 | Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS); 37 | */ 38 | 39 | #define NUMFLAKES 10 40 | #define XPOS 0 41 | #define YPOS 1 42 | #define DELTAY 2 43 | 44 | #define LOGO16_GLCD_HEIGHT 16 45 | #define LOGO16_GLCD_WIDTH 16 46 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 47 | { B00000000, B11000000, 48 | B00000001, B11000000, 49 | B00000001, B11000000, 50 | B00000011, B11100000, 51 | B11110011, B11100000, 52 | B11111110, B11111000, 53 | B01111110, B11111111, 54 | B00110011, B10011111, 55 | B00011111, B11111100, 56 | B00001101, B01110000, 57 | B00011011, B10100000, 58 | B00111111, B11100000, 59 | B00111111, B11110000, 60 | B01111100, B11110000, 61 | B01110000, B01110000, 62 | B00000000, B00110000 }; 63 | 64 | #if (SSD1306_LCDHEIGHT != 64) 65 | #error("Height incorrect, please fix Adafruit_SSD1306.h!"); 66 | #endif 67 | 68 | void setup() { 69 | Serial.begin(9600); 70 | 71 | // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) 72 | display.begin(SSD1306_SWITCHCAPVCC); 73 | // init done 74 | 75 | // Show image buffer on the display hardware. 76 | // Since the buffer is intialized with an Adafruit splashscreen 77 | // internally, this will display the splashscreen. 78 | display.display(); 79 | delay(2000); 80 | 81 | // Clear the buffer. 82 | display.clearDisplay(); 83 | 84 | // draw a single pixel 85 | display.drawPixel(10, 10, WHITE); 86 | // Show the display buffer on the hardware. 87 | // NOTE: You _must_ call display after making any drawing commands 88 | // to make them visible on the display hardware! 89 | display.display(); 90 | delay(2000); 91 | display.clearDisplay(); 92 | 93 | // draw many lines 94 | testdrawline(); 95 | display.display(); 96 | delay(2000); 97 | display.clearDisplay(); 98 | 99 | // draw rectangles 100 | testdrawrect(); 101 | display.display(); 102 | delay(2000); 103 | display.clearDisplay(); 104 | 105 | // draw multiple rectangles 106 | testfillrect(); 107 | display.display(); 108 | delay(2000); 109 | display.clearDisplay(); 110 | 111 | // draw mulitple circles 112 | testdrawcircle(); 113 | display.display(); 114 | delay(2000); 115 | display.clearDisplay(); 116 | 117 | // draw a white circle, 10 pixel radius 118 | display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); 119 | display.display(); 120 | delay(2000); 121 | display.clearDisplay(); 122 | 123 | testdrawroundrect(); 124 | delay(2000); 125 | display.clearDisplay(); 126 | 127 | testfillroundrect(); 128 | delay(2000); 129 | display.clearDisplay(); 130 | 131 | testdrawtriangle(); 132 | delay(2000); 133 | display.clearDisplay(); 134 | 135 | testfilltriangle(); 136 | delay(2000); 137 | display.clearDisplay(); 138 | 139 | // draw the first ~12 characters in the font 140 | testdrawchar(); 141 | display.display(); 142 | delay(2000); 143 | display.clearDisplay(); 144 | 145 | // draw scrolling text 146 | testscrolltext(); 147 | delay(2000); 148 | display.clearDisplay(); 149 | 150 | // text display tests 151 | display.setTextSize(1); 152 | display.setTextColor(WHITE); 153 | display.setCursor(0,0); 154 | display.println("Hello, world!"); 155 | display.setTextColor(BLACK, WHITE); // 'inverted' text 156 | display.println(3.141592); 157 | display.setTextSize(2); 158 | display.setTextColor(WHITE); 159 | display.print("0x"); display.println(0xDEADBEEF, HEX); 160 | display.display(); 161 | delay(2000); 162 | display.clearDisplay(); 163 | 164 | // miniature bitmap display 165 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 166 | display.display(); 167 | 168 | // invert the display 169 | display.invertDisplay(true); 170 | delay(1000); 171 | display.invertDisplay(false); 172 | delay(1000); 173 | display.clearDisplay(); 174 | 175 | // draw a bitmap icon and 'animate' movement 176 | testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); 177 | } 178 | 179 | 180 | void loop() { 181 | 182 | } 183 | 184 | 185 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 186 | uint8_t icons[NUMFLAKES][3]; 187 | 188 | // initialize 189 | for (uint8_t f=0; f< NUMFLAKES; f++) { 190 | icons[f][XPOS] = random(display.width()); 191 | icons[f][YPOS] = 0; 192 | icons[f][DELTAY] = random(5) + 1; 193 | 194 | Serial.print("x: "); 195 | Serial.print(icons[f][XPOS], DEC); 196 | Serial.print(" y: "); 197 | Serial.print(icons[f][YPOS], DEC); 198 | Serial.print(" dy: "); 199 | Serial.println(icons[f][DELTAY], DEC); 200 | } 201 | 202 | while (1) { 203 | // draw each icon 204 | for (uint8_t f=0; f< NUMFLAKES; f++) { 205 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE); 206 | } 207 | display.display(); 208 | delay(200); 209 | 210 | // then erase it + move it 211 | for (uint8_t f=0; f< NUMFLAKES; f++) { 212 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); 213 | // move it 214 | icons[f][YPOS] += icons[f][DELTAY]; 215 | // if its gone, reinit 216 | if (icons[f][YPOS] > display.height()) { 217 | icons[f][XPOS] = random(display.width()); 218 | icons[f][YPOS] = 0; 219 | icons[f][DELTAY] = random(5) + 1; 220 | } 221 | } 222 | } 223 | } 224 | 225 | 226 | void testdrawchar(void) { 227 | display.setTextSize(1); 228 | display.setTextColor(WHITE); 229 | display.setCursor(0,0); 230 | 231 | for (uint8_t i=0; i < 168; i++) { 232 | if (i == '\n') continue; 233 | display.write(i); 234 | if ((i > 0) && (i % 21 == 0)) 235 | display.println(); 236 | } 237 | display.display(); 238 | } 239 | 240 | void testdrawcircle(void) { 241 | for (int16_t i=0; i0; i-=5) { 269 | display.fillTriangle(display.width()/2, display.height()/2-i, 270 | display.width()/2-i, display.height()/2+i, 271 | display.width()/2+i, display.height()/2+i, WHITE); 272 | if (color == WHITE) color = BLACK; 273 | else color = WHITE; 274 | display.display(); 275 | } 276 | } 277 | 278 | void testdrawroundrect(void) { 279 | for (int16_t i=0; i=0; i-=4) { 319 | display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); 320 | display.display(); 321 | } 322 | delay(250); 323 | 324 | display.clearDisplay(); 325 | for (int16_t i=display.width()-1; i>=0; i-=4) { 326 | display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); 327 | display.display(); 328 | } 329 | for (int16_t i=display.height()-1; i>=0; i-=4) { 330 | display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); 331 | display.display(); 332 | } 333 | delay(250); 334 | 335 | display.clearDisplay(); 336 | for (int16_t i=0; i http://www.adafruit.com/category/63_98 6 | 7 | This example is for a 64x48 size display using I2C to communicate 8 | 3 pins are required to interface (2 I2C and one reset) 9 | 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 | BSD license, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | // SCL GPIO5 25 | // SDA GPIO4 26 | #define OLED_RESET 0 // GPIO0 27 | Adafruit_SSD1306 display(OLED_RESET); 28 | 29 | #define NUMFLAKES 10 30 | #define XPOS 0 31 | #define YPOS 1 32 | #define DELTAY 2 33 | 34 | 35 | #define LOGO16_GLCD_HEIGHT 16 36 | #define LOGO16_GLCD_WIDTH 16 37 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 38 | { B00000000, B11000000, 39 | B00000001, B11000000, 40 | B00000001, B11000000, 41 | B00000011, B11100000, 42 | B11110011, B11100000, 43 | B11111110, B11111000, 44 | B01111110, B11111111, 45 | B00110011, B10011111, 46 | B00011111, B11111100, 47 | B00001101, B01110000, 48 | B00011011, B10100000, 49 | B00111111, B11100000, 50 | B00111111, B11110000, 51 | B01111100, B11110000, 52 | B01110000, B01110000, 53 | B00000000, B00110000 }; 54 | 55 | #if (SSD1306_LCDHEIGHT != 48) 56 | #error("Height incorrect, please fix Adafruit_SSD1306.h!"); 57 | #endif 58 | 59 | void setup() { 60 | Serial.begin(9600); 61 | 62 | // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) 63 | display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48) 64 | // init done 65 | 66 | // Show image buffer on the display hardware. 67 | // Since the buffer is intialized with an Adafruit splashscreen 68 | // internally, this will display the splashscreen. 69 | display.display(); 70 | delay(2000); 71 | 72 | // Clear the buffer. 73 | display.clearDisplay(); 74 | 75 | // draw a single pixel 76 | display.drawPixel(10, 10, WHITE); 77 | // Show the display buffer on the hardware. 78 | // NOTE: You _must_ call display after making any drawing commands 79 | // to make them visible on the display hardware! 80 | display.display(); 81 | delay(2000); 82 | display.clearDisplay(); 83 | 84 | // draw many lines 85 | testdrawline(); 86 | display.display(); 87 | delay(2000); 88 | display.clearDisplay(); 89 | 90 | // draw rectangles 91 | testdrawrect(); 92 | display.display(); 93 | delay(2000); 94 | display.clearDisplay(); 95 | 96 | // draw multiple rectangles 97 | testfillrect(); 98 | display.display(); 99 | delay(2000); 100 | display.clearDisplay(); 101 | 102 | // draw mulitple circles 103 | testdrawcircle(); 104 | display.display(); 105 | delay(2000); 106 | display.clearDisplay(); 107 | 108 | // draw a white circle, 10 pixel radius 109 | display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); 110 | display.display(); 111 | delay(2000); 112 | display.clearDisplay(); 113 | 114 | testdrawroundrect(); 115 | delay(2000); 116 | display.clearDisplay(); 117 | 118 | testfillroundrect(); 119 | delay(2000); 120 | display.clearDisplay(); 121 | 122 | testdrawtriangle(); 123 | delay(2000); 124 | display.clearDisplay(); 125 | 126 | testfilltriangle(); 127 | delay(2000); 128 | display.clearDisplay(); 129 | 130 | // draw the first ~12 characters in the font 131 | testdrawchar(); 132 | display.display(); 133 | delay(2000); 134 | display.clearDisplay(); 135 | 136 | // draw scrolling text 137 | testscrolltext(); 138 | delay(2000); 139 | display.clearDisplay(); 140 | 141 | // text display tests 142 | display.setTextSize(1); 143 | display.setTextColor(WHITE); 144 | display.setCursor(0,0); 145 | display.println("Hello, world!"); 146 | display.setTextColor(BLACK, WHITE); // 'inverted' text 147 | display.println(3.141592); 148 | display.setTextSize(2); 149 | display.setTextColor(WHITE); 150 | display.print("0x"); display.println(0xDEADBEEF, HEX); 151 | display.display(); 152 | delay(2000); 153 | display.clearDisplay(); 154 | 155 | // miniature bitmap display 156 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 157 | display.display(); 158 | delay(1); 159 | 160 | // invert the display 161 | display.invertDisplay(true); 162 | delay(1000); 163 | display.invertDisplay(false); 164 | delay(1000); 165 | display.clearDisplay(); 166 | 167 | // draw a bitmap icon and 'animate' movement 168 | testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); 169 | } 170 | 171 | 172 | void loop() { 173 | 174 | } 175 | 176 | 177 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 178 | uint8_t icons[NUMFLAKES][3]; 179 | 180 | // initialize 181 | for (uint8_t f=0; f< NUMFLAKES; f++) { 182 | icons[f][XPOS] = random(display.width()); 183 | icons[f][YPOS] = 0; 184 | icons[f][DELTAY] = random(5) + 1; 185 | 186 | Serial.print("x: "); 187 | Serial.print(icons[f][XPOS], DEC); 188 | Serial.print(" y: "); 189 | Serial.print(icons[f][YPOS], DEC); 190 | Serial.print(" dy: "); 191 | Serial.println(icons[f][DELTAY], DEC); 192 | } 193 | 194 | while (1) { 195 | // draw each icon 196 | for (uint8_t f=0; f< NUMFLAKES; f++) { 197 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE); 198 | } 199 | display.display(); 200 | delay(200); 201 | 202 | // then erase it + move it 203 | for (uint8_t f=0; f< NUMFLAKES; f++) { 204 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); 205 | // move it 206 | icons[f][YPOS] += icons[f][DELTAY]; 207 | // if its gone, reinit 208 | if (icons[f][YPOS] > display.height()) { 209 | icons[f][XPOS] = random(display.width()); 210 | icons[f][YPOS] = 0; 211 | icons[f][DELTAY] = random(5) + 1; 212 | } 213 | } 214 | } 215 | } 216 | 217 | 218 | void testdrawchar(void) { 219 | display.setTextSize(1); 220 | display.setTextColor(WHITE); 221 | display.setCursor(0,0); 222 | 223 | for (uint8_t i=0; i < 168; i++) { 224 | if (i == '\n') continue; 225 | display.write(i); 226 | if ((i > 0) && (i % 21 == 0)) 227 | display.println(); 228 | } 229 | display.display(); 230 | delay(1); 231 | } 232 | 233 | void testdrawcircle(void) { 234 | for (int16_t i=0; i0; i-=5) { 265 | display.fillTriangle(display.width()/2, display.height()/2-i, 266 | display.width()/2-i, display.height()/2+i, 267 | display.width()/2+i, display.height()/2+i, WHITE); 268 | if (color == WHITE) color = BLACK; 269 | else color = WHITE; 270 | display.display(); 271 | delay(1); 272 | } 273 | } 274 | 275 | void testdrawroundrect(void) { 276 | for (int16_t i=0; i=0; i-=4) { 322 | display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); 323 | display.display(); 324 | delay(1); 325 | } 326 | delay(250); 327 | 328 | display.clearDisplay(); 329 | for (int16_t i=display.width()-1; i>=0; i-=4) { 330 | display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); 331 | display.display(); 332 | delay(1); 333 | } 334 | for (int16_t i=display.height()-1; i>=0; i-=4) { 335 | display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); 336 | display.display(); 337 | delay(1); 338 | } 339 | delay(250); 340 | 341 | display.clearDisplay(); 342 | for (int16_t i=0; i 5 | sentence=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 OLEDs! 6 | paragraph=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 OLEDs! 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit_SSD1306 9 | architectures=* 10 | -------------------------------------------------------------------------------- /lib/Adafruit_SSD1306-esp8266-64x48/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /lib/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for the project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link to executable file. 4 | 5 | The source code of each library should be placed in separate directory, like 6 | "lib/private_lib/[here are source files]". 7 | 8 | For example, see how can be organized `Foo` and `Bar` libraries: 9 | 10 | |--lib 11 | | |--Bar 12 | | | |--docs 13 | | | |--examples 14 | | | |--src 15 | | | |- Bar.c 16 | | | |- Bar.h 17 | | |--Foo 18 | | | |- Foo.c 19 | | | |- Foo.h 20 | | |- readme.txt --> THIS FILE 21 | |- platformio.ini 22 | |--src 23 | |- main.c 24 | 25 | Then in `src/main.c` you should use: 26 | 27 | #include 28 | #include 29 | 30 | // rest H/C/CPP code 31 | 32 | PlatformIO will find your libraries automatically, configure preprocessor's 33 | include paths and build them. 34 | 35 | See additional options for PlatformIO Library Dependency Finder `lib_*`: 36 | 37 | http://docs.platformio.org/en/latest/projectconf.html#lib-install 38 | 39 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | # 2 | # Project Configuration File 3 | # 4 | # A detailed documentation with the EXAMPLES is located here: 5 | # http://docs.platformio.org/en/latest/projectconf.html 6 | # 7 | 8 | # A sign `#` at the beginning of the line indicates a comment 9 | # Comment lines are ignored. 10 | 11 | # Simple and base environment 12 | # [env:mybaseenv] 13 | # platform = %INSTALLED_PLATFORM_NAME_HERE% 14 | # framework = 15 | # board = 16 | # 17 | # Automatic targets - enable auto-uploading 18 | # targets = upload 19 | 20 | [env:d1_mini] 21 | platform = espressif 22 | framework = arduino 23 | board = d1_mini 24 | 25 | # decrease to 115200 if you're facing upload problems 26 | upload_speed = 921600 27 | -------------------------------------------------------------------------------- /server-script/weather_script.php: -------------------------------------------------------------------------------- 1 | language=it-IT 10 | by Mattia - mattia.fiorini(at)gmail.com 11 | */ 12 | 13 | $json_string = file_get_contents("https://api.weather.com/v2/pws/observations/current?stationId={yourStationId}&format=json&units=m&apiKey={your API key}"); 14 | 15 | $predpoved_json_string = file_get_contents("https://api.weather.com/v3/wx/forecast/daily/5day?geocode={your lat DD.dd},{your lon DD.dd}&format=json&units=m&language=it-IT&apiKey={your API key}"); 16 | 17 | $parsed_json = json_decode($json_string); 18 | $parsed_predpoved = json_decode($predpoved_json_string); 19 | 20 | $forecast = $parsed_predpoved; 21 | 22 | $temp_c = $parsed_json->{'observations'}[0]->{'metric'}->{'temp'}; 23 | $pressure = $parsed_json->{'observations'}[0]->{'metric'}->{'pressure'}; 24 | $weather = explode(".", $forecast->{'narrative'}[0]); 25 | $weather= $weather[0]; 26 | 27 | 28 | $p1_temperature_h = $forecast->{'temperatureMax'}[1]; 29 | $p1_temperature_l = $forecast->{'temperatureMin'}[1]; 30 | $p1_cond = explode(".", $forecast->{'narrative'}[1]); 31 | $p1_cond= $p1_cond[0]; 32 | 33 | $p2_temperature_h = $forecast->{'temperatureMax'}[2]; 34 | $p2_temperature_l = $forecast->{'temperatureMin'}[2]; 35 | $p2_cond = explode(".", $forecast->{'narrative'}[2]); 36 | $p2_cond= $p2_cond[0]; 37 | 38 | $p3_temperature_h = $forecast->{'temperatureMax'}[3]; 39 | $p3_temperature_l = $forecast->{'temperatureMin'}[3]; 40 | $p3_cond = explode(".", $forecast->{'narrative'}[3]); 41 | $p3_cond= $p3_cond[0]; 42 | 43 | /* Print values for ESP8266 / Wemos. Semicolon delimited data, starting with "FCST:". */ 44 | 45 | echo "FCST:" . $temp_c . ";" . $pressure . ";" . $weather . ";" . $p1_temperature_h . ";" . $p1_temperature_l . ";" . $p1_cond . ";" . $p2_temperature_h . ";" . $p2_temperature_l . ";" . $p2_cond . ";" . $p3_temperature_h . ";" . $p3_temperature_l . ";" . $p3_cond . ";" . "\n"; 46 | ?> 47 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define WIFI_AP "Your wifi SSID" 9 | #define WIFI_PASSWORD "Your wifi password" 10 | #define SCRIPT_URL "http://your.server.com/weather_script.php" 11 | 12 | // SCL GPIO5 13 | // SDA GPIO4 14 | #define OLED_RESET 0 // GPIO0 15 | Adafruit_SSD1306 display(OLED_RESET); 16 | 17 | #define LOGO16_GLCD_HEIGHT 16 18 | #define LOGO16_GLCD_WIDTH 16 19 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 20 | { B00000000, B11000000, 21 | B00000001, B11000000, 22 | B00000001, B11000000, 23 | B00000011, B11100000, 24 | B11110011, B11100000, 25 | B11111110, B11111000, 26 | B01111110, B11111111, 27 | B00110011, B10011111, 28 | B00011111, B11111100, 29 | B00001101, B01110000, 30 | B00011011, B10100000, 31 | B00111111, B11100000, 32 | B00111111, B11110000, 33 | B01111100, B11110000, 34 | B01110000, B01110000, 35 | B00000000, B00110000 }; 36 | 37 | #if (SSD1306_LCDHEIGHT != 48) 38 | #error("Height incorrect, please fix Adafruit_SSD1306.h!"); 39 | #endif 40 | 41 | void showData(String caption, String caption2, String value, String units) { 42 | display.setTextSize(1); 43 | display.setTextColor(WHITE); 44 | display.setCursor(0,0); 45 | display.clearDisplay(); 46 | display.println(caption); 47 | display.setCursor(0,10); 48 | display.println(caption2); 49 | display.setTextSize(2); 50 | display.setCursor(0,20); 51 | display.println(value); 52 | display.setTextSize(1); 53 | display.setCursor(0,40); 54 | display.println(units); 55 | display.display(); 56 | delay(1); 57 | } 58 | 59 | void showDataSmall(String caption, String caption2, String value, String units) { 60 | display.setTextSize(1); 61 | display.setTextColor(WHITE); 62 | display.setCursor(0,0); 63 | display.clearDisplay(); 64 | display.println(caption); 65 | display.setCursor(0,10); 66 | display.println(value); 67 | display.setTextSize(1); 68 | display.setCursor(0,30); 69 | display.println(units); 70 | display.display(); 71 | delay(1); 72 | } 73 | 74 | void setup() { 75 | 76 | Serial.begin(115200); 77 | // Serial.setDebugOutput(true); 78 | 79 | Serial.println(); 80 | Serial.println(); 81 | Serial.println(); 82 | 83 | display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48) 84 | display.display(); 85 | display.clearDisplay(); 86 | 87 | for(uint8_t t = 4; t > 0; t--) { 88 | Serial.printf("[SETUP] WAIT %d...\n", t); 89 | Serial.flush(); 90 | delay(1000); 91 | } 92 | 93 | // connect to wifi 94 | WiFi.begin(WIFI_AP, WIFI_PASSWORD); 95 | 96 | while (WiFi.status() != WL_CONNECTED) { 97 | delay(500); 98 | Serial.print("."); 99 | } 100 | 101 | Serial.println(""); 102 | Serial.println("WiFi connected"); 103 | Serial.println("IP address: "); 104 | Serial.println(WiFi.localIP()); 105 | Serial.println("--------------------------"); 106 | } 107 | 108 | void loop() { 109 | // wait for WiFi connection 110 | if((WiFi.status() == WL_CONNECTED)) { 111 | 112 | HTTPClient http; 113 | 114 | Serial.print("[HTTP] begin...\n"); 115 | // GET to PHP script where data are being parsed and sent to D1 mini. 116 | // At the backend there is also default location specified. 117 | http.begin(SCRIPT_URL); //HTTP GET 118 | 119 | Serial.print("[HTTP] GET...\n"); 120 | // start connection and send HTTP header 121 | int httpCode = http.GET(); 122 | 123 | // httpCode will be negative on error 124 | if(httpCode > 0) { 125 | // HTTP header has been send and Server response header has been handled 126 | Serial.printf("[HTTP] GET... code: %d\n", httpCode); 127 | 128 | // file found at server 129 | if(httpCode == HTTP_CODE_OK) { 130 | String payload = http.getString(); 131 | Serial.println(payload); 132 | 133 | char *p = (char*)payload.c_str(); 134 | char *str; 135 | int i = 0; 136 | String temperature = ""; 137 | while ((str = strtok_r(p, ";", &p)) != NULL) // delimiter is the semicolon 138 | { 139 | String s = String(str); 140 | 141 | switch (i) // switch index of displayed data 142 | { 143 | case 0: 144 | temperature = String(str).substring(5); 145 | showData("Actual", "temp", temperature, "deg. C"); 146 | delay(15000); 147 | break; 148 | 149 | case 1: 150 | showData("Actual", "pressure", s, "HPa"); 151 | delay(5000); 152 | break; 153 | 154 | case 2: 155 | s.replace(" ", "\n"); 156 | showDataSmall("Weather", "", s, ""); 157 | delay(5000); 158 | break; 159 | 160 | case 3: 161 | showData("Tommorow", "temp", s, "deg. C"); 162 | delay(5000); 163 | break; 164 | 165 | case 4: 166 | showData("Tommorow", "at night", s, "deg. C"); 167 | delay(5000); 168 | break; 169 | 170 | case 5: 171 | s.replace(" ", "\n"); 172 | showDataSmall("Tommorow", "", s, ""); 173 | delay(5000); 174 | break; 175 | 176 | case 6: 177 | showData("Day after", "temp", s, "deg. C"); 178 | delay(5000); 179 | break; 180 | 181 | case 7: 182 | showData("Day after", "at night", s, "deg. C"); 183 | delay(5000); 184 | break; 185 | 186 | case 8: 187 | s.replace(" ", "\n"); 188 | showDataSmall("Day after", "", s, ""); 189 | delay(5000); 190 | break; 191 | 192 | case 9: 193 | showData("In 3 days", "temp", s, "deg. C"); 194 | delay(5000); 195 | break; 196 | 197 | case 10: 198 | showData("In 3 days", "at night", s, "deg. C"); 199 | delay(5000); 200 | break; 201 | 202 | case 11: 203 | s.replace(" ", "\n"); 204 | showDataSmall("In 3 days", "", s, ""); 205 | delay(5000); 206 | break; 207 | } 208 | i++; 209 | } 210 | 211 | showData("Actual", "temp", temperature, "deg. C"); 212 | } 213 | } else { 214 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 215 | } 216 | 217 | http.end(); 218 | } 219 | 220 | // Waits a minute so we don't overwhelm the data source's requests limit. Check API and PHP script. 221 | delay(60000); 222 | } 223 | --------------------------------------------------------------------------------