├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── .gitignore ├── Adafruit_HX8357.cpp ├── Adafruit_HX8357.h ├── README.md ├── examples ├── bitmapdraw_featherwing │ ├── .leonardo.test.skip │ ├── .mega2560.test.skip │ ├── .qtpy_m0.test.skip │ ├── .trinket_m0.test.skip │ └── bitmapdraw_featherwing.ino ├── breakouttouchpaint │ ├── .esp8266.test.skip │ └── breakouttouchpaint.ino ├── gfxbuttontest_featherwing │ ├── .mega2560.test.skip │ ├── .qtpy_m0.test.skip │ ├── .trinket_m0.test.skip │ └── gfxbuttontest_featherwing.ino ├── graphicstest │ └── graphicstest.ino ├── graphicstest_featherwing │ ├── .mega2560.test.skip │ ├── .qtpy_m0.test.skip │ ├── .trinket_m0.test.skip │ └── graphicstest_featherwing.ino └── touchpaint_featherwing │ ├── .mega2560.test.skip │ ├── .qtpy_m0.test.skip │ ├── .trinket_m0.test.skip │ └── touchpaint_featherwing.ino ├── jumpers.bmp └── library.properties /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: pre-install 20 | run: bash ci/actions_install.sh 21 | 22 | - name: test platforms 23 | run: python3 ci/build_platform.py main_platforms 24 | 25 | - name: clang 26 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 27 | 28 | - name: doxygen 29 | env: 30 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 31 | PRETTYNAME : "Adafruit HX8357 Arduino Library" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Our handy .gitignore for automation ease 2 | Doxyfile* 3 | doxygen_sqlite3.db 4 | html 5 | -------------------------------------------------------------------------------- /Adafruit_HX8357.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_HX8357.cpp 3 | * 4 | * @mainpage Adafruit HX8357 TFT Displays 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * This is the documentation for Adafruit's HX8357 driver for the Arduino 9 | * platform. 10 | * 11 | * This library works with the Adafruit 3.5" TFT 320x480 + Touchscreen Breakout 12 | * http://www.adafruit.com/products/2050 13 | * 14 | * Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers 15 | * https://www.adafruit.com/product/3651 16 | * 17 | * These displays use SPI to communicate. This requires 4 pins (MOSI, 18 | * SCK, select, data/command) and optionally a reset pin. Hardware SPI 19 | * or 'bitbang' software SPI are both supported. 20 | * 21 | * Adafruit invests time and resources providing this open source code, 22 | * please support Adafruit and open-source hardware by purchasing 23 | * products from Adafruit! 24 | * 25 | * @section dependencies Dependencies 26 | * 27 | * This library depends on 28 | * Adafruit_GFX being present on your system. Please make sure you have 29 | * installed the latest version before using this library. 30 | * 31 | * @section author Author 32 | * 33 | * Written by Limor Fried/Ladyada for Adafruit Industries, with 34 | * contributions from the open source community. 35 | * 36 | * @section license License 37 | * 38 | * BSD license, all text here must be included in any redistribution. 39 | */ 40 | 41 | #include "Adafruit_HX8357.h" 42 | #include 43 | #include 44 | 45 | #define MADCTL_MY 0x80 ///< Bottom to top 46 | #define MADCTL_MX 0x40 ///< Right to left 47 | #define MADCTL_MV 0x20 ///< Reverse Mode 48 | #define MADCTL_ML 0x10 ///< LCD refresh Bottom to top 49 | #define MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order 50 | #define MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order 51 | #define MADCTL_MH 0x04 ///< LCD refresh right to left 52 | 53 | // THIS REALLY SHOULD GO IN SPITFT (PART OF ADAFRUIT_GFX), 54 | // AND CAN BE FURTHER EXPANDED (e.g. add 12 MHz for M0, 24 for M4), 55 | // BUT TEMPORARILY FOR NOW IT'S HERE: 56 | 57 | #if defined(ARDUINO_ARCH_ARC32) 58 | #define SPI_DEFAULT_FREQ 16000000 59 | #elif defined(__AVR__) || defined(TEENSYDUINO) 60 | #define SPI_DEFAULT_FREQ 8000000 61 | #elif defined(ESP8266) || defined(ARDUINO_MAXIM) 62 | #define SPI_DEFAULT_FREQ 16000000 63 | #elif defined(ESP32) 64 | #define SPI_DEFAULT_FREQ 24000000 65 | #elif defined(RASPI) 66 | #define SPI_DEFAULT_FREQ 24000000 67 | #else 68 | #define SPI_DEFAULT_FREQ 24000000 ///< The default SPI frequency 69 | #endif 70 | 71 | // CONSTRUCTORS, DESTRUCTOR ------------------------------------------------ 72 | 73 | /*! 74 | @brief Constructor for Adafruit_HX8357 displays, using software 75 | (bitbang) SPI. 76 | @param cs 77 | Chip select pin (using Arduino pin numbering). 78 | @param dc 79 | Data/Command pin (using Arduino pin numbering). 80 | @param mosi 81 | SPI MOSI pin (using Arduino pin numbering). 82 | @param sclk 83 | SPI Clock pin (using Arduino pin numbering). 84 | @param rst 85 | Reset pin (Arduino pin numbering, optional, pass -1 if unused). 86 | @param miso 87 | SPI MISO pin (Arduino pin #, optional, pass -1 if unused). 88 | @param type 89 | Display type, HX8357D (default if unspecified) or HX8357B. 90 | @return Adafruit_HX8357 object. 91 | @note Call the object's begin() function before use. 92 | */ 93 | Adafruit_HX8357::Adafruit_HX8357(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk, 94 | int8_t rst, int8_t miso, uint8_t type) 95 | : Adafruit_SPITFT(HX8357_TFTWIDTH, HX8357_TFTHEIGHT, cs, dc, mosi, sclk, 96 | rst, miso), 97 | displayType(type) {} 98 | 99 | /*! 100 | @brief Constructor for Adafruit_HX8357 displays, using the default 101 | hardware SPI interface. 102 | @param cs 103 | Chip select pin (using Arduino pin numbering). 104 | @param dc 105 | Data/Command pin (using Arduino pin numbering). 106 | @param rst 107 | Reset pin (Arduino pin numbering, optional, pass -1 if unused). 108 | @param type 109 | Display type, HX8357D (default if unspecified) or HX8357B. 110 | @return Adafruit_HX8357 object. 111 | @note Call the object's begin() function before use. 112 | */ 113 | Adafruit_HX8357::Adafruit_HX8357(int8_t cs, int8_t dc, int8_t rst, uint8_t type) 114 | : Adafruit_SPITFT(HX8357_TFTWIDTH, HX8357_TFTHEIGHT, cs, dc, rst), 115 | displayType(type) {} 116 | 117 | #if !defined(ESP8266) 118 | /*! 119 | @brief Constructor for Adafruit_HX8357 displays, using an arbitrary 120 | SPI interface. 121 | @param spi 122 | SPI peripheral to use. 123 | @param cs 124 | Chip select pin (using Arduino pin numbering). 125 | @param dc 126 | Data/Command pin (using Arduino pin numbering). 127 | @param rst 128 | Reset pin (Arduino pin numbering, optional, pass -1 if unused). 129 | @param type 130 | Display type, HX8357D (default if unspecified) or HX8357B. 131 | @return Adafruit_HX8357 object. 132 | @note Call the object's begin() function before use. 133 | */ 134 | Adafruit_HX8357::Adafruit_HX8357(SPIClass *spi, int8_t cs, int8_t dc, 135 | int8_t rst, uint8_t type) 136 | : Adafruit_SPITFT(HX8357_TFTWIDTH, HX8357_TFTHEIGHT, spi, cs, dc, rst), 137 | displayType(type) {} 138 | #endif // end !ESP8266 139 | 140 | /**************************************************************************/ 141 | /*! 142 | @brief Constructor for Adafruit_HX8357 displays, using parallel 143 | interface. 144 | @param busWidth If tft16 (enumeration in Adafruit_SPITFT.h), is a 145 | 16-bit interface, else 8-bit. 146 | @param d0 Data pin 0 (MUST be a byte- or word-aligned LSB of a 147 | PORT register -- pins 1-n are extrapolated from this). 148 | @param wr Write strobe pin # (required). 149 | @param dc Data/Command pin # (required). 150 | @param cs Chip select pin # (optional, pass -1 if unused and CS 151 | is tied to GND). 152 | @param rst Reset pin # (optional, pass -1 if unused). 153 | @param rd Read strobe pin # (optional, pass -1 if unused). 154 | */ 155 | /**************************************************************************/ 156 | Adafruit_HX8357::Adafruit_HX8357(tftBusWidth busWidth, int8_t d0, int8_t wr, 157 | int8_t dc, int8_t cs, int8_t rst, int8_t rd) 158 | : Adafruit_SPITFT(HX8357_TFTWIDTH, HX8357_TFTHEIGHT, busWidth, d0, wr, dc, 159 | cs, rst, rd) {} 160 | 161 | /*! 162 | @brief Destructor for Adafruit_HX8357 object. 163 | @return None (void). 164 | */ 165 | Adafruit_HX8357::~Adafruit_HX8357(void) {} 166 | 167 | // INIT DISPLAY ------------------------------------------------------------ 168 | 169 | static const uint8_t PROGMEM 170 | initb[] = 171 | { 172 | HX8357B_SETPOWER, 173 | 3, 174 | 0x44, 175 | 0x41, 176 | 0x06, 177 | HX8357B_SETVCOM, 178 | 2, 179 | 0x40, 180 | 0x10, 181 | HX8357B_SETPWRNORMAL, 182 | 2, 183 | 0x05, 184 | 0x12, 185 | HX8357B_SET_PANEL_DRIVING, 186 | 5, 187 | 0x14, 188 | 0x3b, 189 | 0x00, 190 | 0x02, 191 | 0x11, 192 | HX8357B_SETDISPLAYFRAME, 193 | 1, 194 | 0x0c, // 6.8mhz 195 | HX8357B_SETPANELRELATED, 196 | 1, 197 | 0x01, // BGR 198 | 0xEA, 199 | 3, // seq_undefined1, 3 args 200 | 0x03, 201 | 0x00, 202 | 0x00, 203 | 0xEB, 204 | 4, // undef2, 4 args 205 | 0x40, 206 | 0x54, 207 | 0x26, 208 | 0xdb, 209 | HX8357B_SETGAMMA, 210 | 12, 211 | 0x00, 212 | 0x15, 213 | 0x00, 214 | 0x22, 215 | 0x00, 216 | 0x08, 217 | 0x77, 218 | 0x26, 219 | 0x66, 220 | 0x22, 221 | 0x04, 222 | 0x00, 223 | HX8357_MADCTL, 224 | 1, 225 | 0xC0, 226 | HX8357_COLMOD, 227 | 1, 228 | 0x55, 229 | HX8357_PASET, 230 | 4, 231 | 0x00, 232 | 0x00, 233 | 0x01, 234 | 0xDF, 235 | HX8357_CASET, 236 | 4, 237 | 0x00, 238 | 0x00, 239 | 0x01, 240 | 0x3F, 241 | HX8357B_SETDISPMODE, 242 | 1, 243 | 0x00, // CPU (DBI) and internal oscillation ?? 244 | HX8357_SLPOUT, 245 | 0x80 + 120 / 5, // Exit sleep, then delay 120 ms 246 | HX8357_DISPON, 247 | 0x80 + 10 / 5, // Main screen turn on, delay 10 ms 248 | 0 // END OF COMMAND LIST 249 | }, 250 | initd[] = { 251 | HX8357_SWRESET, 252 | 0x80 + 100 / 5, // Soft reset, then delay 10 ms 253 | HX8357D_SETC, 254 | 3, 255 | 0xFF, 256 | 0x83, 257 | 0x57, 258 | 0xFF, 259 | 0x80 + 500 / 5, // No command, just delay 300 ms 260 | HX8357_SETRGB, 261 | 4, 262 | 0x80, 263 | 0x00, 264 | 0x06, 265 | 0x06, // 0x80 enables SDO pin (0x00 disables) 266 | HX8357D_SETCOM, 267 | 1, 268 | 0x25, // -1.52V 269 | HX8357_SETOSC, 270 | 1, 271 | 0x68, // Normal mode 70Hz, Idle mode 55 Hz 272 | HX8357_SETPANEL, 273 | 1, 274 | 0x05, // BGR, Gate direction swapped 275 | HX8357_SETPWR1, 276 | 6, 277 | 0x00, // Not deep standby 278 | 0x15, // BT 279 | 0x1C, // VSPR 280 | 0x1C, // VSNR 281 | 0x83, // AP 282 | 0xAA, // FS 283 | HX8357D_SETSTBA, 284 | 6, 285 | 0x50, // OPON normal 286 | 0x50, // OPON idle 287 | 0x01, // STBA 288 | 0x3C, // STBA 289 | 0x1E, // STBA 290 | 0x08, // GEN 291 | HX8357D_SETCYC, 292 | 7, 293 | 0x02, // NW 0x02 294 | 0x40, // RTN 295 | 0x00, // DIV 296 | 0x2A, // DUM 297 | 0x2A, // DUM 298 | 0x0D, // GDON 299 | 0x78, // GDOFF 300 | HX8357D_SETGAMMA, 301 | 34, 302 | 0x02, 303 | 0x0A, 304 | 0x11, 305 | 0x1d, 306 | 0x23, 307 | 0x35, 308 | 0x41, 309 | 0x4b, 310 | 0x4b, 311 | 0x42, 312 | 0x3A, 313 | 0x27, 314 | 0x1B, 315 | 0x08, 316 | 0x09, 317 | 0x03, 318 | 0x02, 319 | 0x0A, 320 | 0x11, 321 | 0x1d, 322 | 0x23, 323 | 0x35, 324 | 0x41, 325 | 0x4b, 326 | 0x4b, 327 | 0x42, 328 | 0x3A, 329 | 0x27, 330 | 0x1B, 331 | 0x08, 332 | 0x09, 333 | 0x03, 334 | 0x00, 335 | 0x01, 336 | HX8357_COLMOD, 337 | 1, 338 | 0x55, // 16 bit 339 | HX8357_MADCTL, 340 | 1, 341 | 0xC0, 342 | HX8357_TEON, 343 | 1, 344 | 0x00, // TW off 345 | HX8357_TEARLINE, 346 | 2, 347 | 0x00, 348 | 0x02, 349 | HX8357_SLPOUT, 350 | 0x80 + 150 / 5, // Exit Sleep, then delay 150 ms 351 | HX8357_DISPON, 352 | 0x80 + 50 / 5, // Main screen turn on, delay 50 ms 353 | 0, // END OF COMMAND LIST 354 | }; 355 | 356 | /*! 357 | @brief Initialize HX8357 chip. Connects to the HX8357 over SPI and 358 | sends initialization commands. 359 | @param freq 360 | SPI bitrate -- default of 0 will use a (usually) platform- 361 | optimized value, e.g. 8 MHz on AVR, 12 MHz on M0. 362 | @return None (void). 363 | */ 364 | void Adafruit_HX8357::begin(uint32_t freq) { 365 | // Older version of this library accepted a display type as the only 366 | // argument (HX8357D or HX8357B), but SPITFT (part of GFX lib) REQUIRES 367 | // the begin() function instead accept an SPI bitrate (or 0 for default), 368 | // so display type was moved to the constructor. Examples will be 369 | // updated, but just in case there's old code around, we pull shenanigans 370 | // here...the values for HX8357D and HX8357B (0xD and 0xB, respectively) 371 | // would make for absurd SPI bitrates...so if we receive one of those 372 | // values, assume it's old code intending to pass the display type. 373 | // Override the displayType value that was set in the constructor with 374 | // the value passed here, and use the default SPI bitrate for platform. 375 | if (freq == HX8357D) { 376 | displayType = freq; 377 | freq = 0; // Use default SPI frequency 378 | } else if (freq == HX8357B) { 379 | displayType = freq; 380 | freq = 0; // Use default SPI frequency 381 | } 382 | 383 | if (!freq) 384 | freq = SPI_DEFAULT_FREQ; 385 | initSPI(freq); 386 | 387 | const uint8_t *addr = (displayType == HX8357B) ? initb : initd; 388 | uint8_t cmd, x, numArgs; 389 | while ((cmd = pgm_read_byte(addr++)) > 0) { // '0' command ends list 390 | x = pgm_read_byte(addr++); 391 | numArgs = x & 0x7F; 392 | if (cmd != 0xFF) { // '255' is ignored 393 | if (x & 0x80) { // If high bit set, numArgs is a delay time 394 | sendCommand(cmd); 395 | } else { 396 | sendCommand(cmd, addr, numArgs); 397 | addr += numArgs; 398 | } 399 | } 400 | if (x & 0x80) { // If high bit set... 401 | delay(numArgs * 5); // numArgs is actually a delay time (5ms units) 402 | } 403 | } 404 | 405 | _width = HX8357_TFTWIDTH; // Screen dimensions for default rotation 0 406 | _height = HX8357_TFTHEIGHT; 407 | } 408 | 409 | // GFX FUNCTIONS ----------------------------------------------------------- 410 | 411 | /*! 412 | @brief Set origin of (0,0) and orientation of TFT display 413 | @param m 414 | The index for rotation, from 0-3 inclusive 415 | @return None (void). 416 | */ 417 | void Adafruit_HX8357::setRotation(uint8_t m) { 418 | rotation = m & 3; // can't be higher than 3 419 | switch (rotation) { 420 | case 0: 421 | m = MADCTL_MX | MADCTL_MY | MADCTL_RGB; 422 | _width = HX8357_TFTWIDTH; 423 | _height = HX8357_TFTHEIGHT; 424 | break; 425 | case 1: 426 | m = MADCTL_MV | MADCTL_MY | MADCTL_RGB; 427 | _width = HX8357_TFTHEIGHT; 428 | _height = HX8357_TFTWIDTH; 429 | break; 430 | case 2: 431 | m = MADCTL_RGB; 432 | _width = HX8357_TFTWIDTH; 433 | _height = HX8357_TFTHEIGHT; 434 | break; 435 | case 3: 436 | m = MADCTL_MX | MADCTL_MV | MADCTL_RGB; 437 | _width = HX8357_TFTHEIGHT; 438 | _height = HX8357_TFTWIDTH; 439 | break; 440 | } 441 | 442 | sendCommand(HX8357_MADCTL, &m, 1); 443 | } 444 | 445 | /*! 446 | @brief Enable/Disable display color inversion 447 | @param invert 448 | True to invert display, False for normal color. 449 | @return None (void). 450 | */ 451 | void Adafruit_HX8357::invertDisplay(boolean invert) { 452 | sendCommand(invert ? HX8357_INVON : HX8357_INVOFF); 453 | } 454 | 455 | /*! 456 | @brief Set the "address window" - the rectangle we will write to 457 | graphics RAM with the next chunk of SPI data writes. The 458 | HX8357 will automatically wrap the data as each row is filled. 459 | @param x1 460 | Leftmost column of rectangle (screen pixel coordinates). 461 | @param y1 462 | Topmost row of rectangle (screen pixel coordinates). 463 | @param w 464 | Width of rectangle. 465 | @param h 466 | Height of rectangle. 467 | @return None (void). 468 | */ 469 | void Adafruit_HX8357::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t w, 470 | uint16_t h) { 471 | uint16_t x2 = (x1 + w - 1), y2 = (y1 + h - 1); 472 | writeCommand(HX8357_CASET); // Column address set 473 | SPI_WRITE16(x1); 474 | SPI_WRITE16(x2); 475 | writeCommand(HX8357_PASET); // Row address set 476 | SPI_WRITE16(y1); 477 | SPI_WRITE16(y2); 478 | writeCommand(HX8357_RAMWR); // Write to RAM 479 | } 480 | -------------------------------------------------------------------------------- /Adafruit_HX8357.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_HX8357.h 3 | * 4 | * This is the documentation for Adafruit's ILI9341 driver for the Arduino 5 | * platform. 6 | * 7 | * This library works with the Adafruit 3.5" TFT 320x480 + Touchscreen Breakout 8 | * http://www.adafruit.com/products/2050 9 | * 10 | * Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers 11 | * https://www.adafruit.com/product/3651 12 | * 13 | * These displays use SPI to communicate. This requires 4 pins (MOSI, 14 | * SCK, select, data/command) and optionally a reset pin. Hardware SPI 15 | * or 'bitbang' software SPI are both supported. 16 | * 17 | * Adafruit invests time and resources providing this open source code, 18 | * please support Adafruit and open-source hardware by purchasing 19 | * products from Adafruit! 20 | * 21 | * This library depends on 22 | * Adafruit_GFX being present on your system. Please make sure you have 23 | * installed the latest version before using this library. 24 | * 25 | * Written by Limor Fried/Ladyada for Adafruit Industries, with 26 | * contributions from the open source community. 27 | * 28 | * BSD license, all text here must be included in any redistribution. 29 | */ 30 | 31 | #ifndef _ADAFRUIT_HX8357_H 32 | #define _ADAFRUIT_HX8357_H 33 | 34 | #include 35 | 36 | #define HX8357D 0xD ///< Our internal const for D type 37 | #define HX8357B 0xB ///< Our internal const for B type 38 | 39 | #define HX8357_TFTWIDTH 320 ///< 320 pixels wide 40 | #define HX8357_TFTHEIGHT 480 ///< 480 pixels tall 41 | 42 | #define HX8357_NOP 0x00 ///< No op 43 | #define HX8357_SWRESET 0x01 ///< software reset 44 | #define HX8357_RDDID 0x04 ///< Read ID 45 | #define HX8357_RDDST 0x09 ///< (unknown) 46 | 47 | #define HX8357_RDPOWMODE 0x0A ///< Read power mode Read power mode 48 | #define HX8357_RDMADCTL 0x0B ///< Read MADCTL 49 | #define HX8357_RDCOLMOD 0x0C ///< Column entry mode 50 | #define HX8357_RDDIM 0x0D ///< Read display image mode 51 | #define HX8357_RDDSDR 0x0F ///< Read dosplay signal mode 52 | 53 | #define HX8357_SLPIN 0x10 ///< Enter sleep mode 54 | #define HX8357_SLPOUT 0x11 ///< Exit sleep mode 55 | #define HX8357B_PTLON 0x12 ///< Partial mode on 56 | #define HX8357B_NORON 0x13 ///< Normal mode 57 | 58 | #define HX8357_INVOFF 0x20 ///< Turn off invert 59 | #define HX8357_INVON 0x21 ///< Turn on invert 60 | #define HX8357_DISPOFF 0x28 ///< Display on 61 | #define HX8357_DISPON 0x29 ///< Display off 62 | 63 | #define HX8357_CASET 0x2A ///< Column addr set 64 | #define HX8357_PASET 0x2B ///< Page addr set 65 | #define HX8357_RAMWR 0x2C ///< Write VRAM 66 | #define HX8357_RAMRD 0x2E ///< Read VRAm 67 | 68 | #define HX8357B_PTLAR 0x30 ///< (unknown) 69 | #define HX8357_TEON 0x35 ///< Tear enable on 70 | #define HX8357_TEARLINE 0x44 ///< (unknown) 71 | #define HX8357_MADCTL 0x36 ///< Memory access control 72 | #define HX8357_COLMOD 0x3A ///< Color mode 73 | 74 | #define HX8357_SETOSC 0xB0 ///< Set oscillator 75 | #define HX8357_SETPWR1 0xB1 ///< Set power control 76 | #define HX8357B_SETDISPLAY 0xB2 ///< Set display mode 77 | #define HX8357_SETRGB 0xB3 ///< Set RGB interface 78 | #define HX8357D_SETCOM 0xB6 ///< Set VCOM voltage 79 | 80 | #define HX8357B_SETDISPMODE 0xB4 ///< Set display mode 81 | #define HX8357D_SETCYC 0xB4 ///< Set display cycle reg 82 | #define HX8357B_SETOTP 0xB7 ///< Set OTP memory 83 | #define HX8357D_SETC 0xB9 ///< Enable extension command 84 | 85 | #define HX8357B_SET_PANEL_DRIVING 0xC0 ///< Set panel drive mode 86 | #define HX8357D_SETSTBA 0xC0 ///< Set source option 87 | #define HX8357B_SETDGC 0xC1 ///< Set DGC settings 88 | #define HX8357B_SETID 0xC3 ///< Set ID 89 | #define HX8357B_SETDDB 0xC4 ///< Set DDB 90 | #define HX8357B_SETDISPLAYFRAME 0xC5 ///< Set display frame 91 | #define HX8357B_GAMMASET 0xC8 ///< Set Gamma correction 92 | #define HX8357B_SETCABC 0xC9 ///< Set CABC 93 | #define HX8357_SETPANEL 0xCC ///< Set Panel 94 | 95 | #define HX8357B_SETPOWER 0xD0 ///< Set power control 96 | #define HX8357B_SETVCOM 0xD1 ///< Set VCOM 97 | #define HX8357B_SETPWRNORMAL 0xD2 ///< Set power normal 98 | 99 | #define HX8357B_RDID1 0xDA ///< Read ID #1 100 | #define HX8357B_RDID2 0xDB ///< Read ID #2 101 | #define HX8357B_RDID3 0xDC ///< Read ID #3 102 | #define HX8357B_RDID4 0xDD ///< Read ID #4 103 | 104 | #define HX8357D_SETGAMMA 0xE0 ///< Set Gamma 105 | 106 | #define HX8357B_SETGAMMA 0xC8 ///< Set Gamma 107 | #define HX8357B_SETPANELRELATED 0xE9 ///< Set panel related 108 | 109 | // Plan is to move this to GFX header (with different prefix), though 110 | // defines will be kept here for existing code that might be referencing 111 | // them. Some additional ones are in the ILI9341 lib -- add all in GFX! 112 | // Color definitions 113 | #define HX8357_BLACK 0x0000 ///< BLACK color for drawing graphics 114 | #define HX8357_BLUE 0x001F ///< BLUE color for drawing graphics 115 | #define HX8357_RED 0xF800 ///< RED color for drawing graphics 116 | #define HX8357_GREEN 0x07E0 ///< GREEN color for drawing graphics 117 | #define HX8357_CYAN 0x07FF ///< CYAN color for drawing graphics 118 | #define HX8357_MAGENTA 0xF81F ///< MAGENTA color for drawing graphics 119 | #define HX8357_YELLOW 0xFFE0 ///< YELLOW color for drawing graphics 120 | #define HX8357_WHITE 0xFFFF ///< WHITE color for drawing graphics 121 | 122 | /*! 123 | @brief Class to manage hardware interface with HX8357 chipset. 124 | */ 125 | class Adafruit_HX8357 : public Adafruit_SPITFT { 126 | public: 127 | Adafruit_HX8357(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, 128 | int8_t _RST, int8_t _MISO, uint8_t type = HX8357D); 129 | Adafruit_HX8357(int8_t _CS, int8_t _DC, int8_t _RST = -1, 130 | uint8_t type = HX8357D); 131 | #if !defined(ESP8266) 132 | Adafruit_HX8357(SPIClass *spi, int8_t _CS, int8_t _DC, int8_t _RST = -1, 133 | uint8_t type = HX8357D); 134 | #endif // end !ESP8266 135 | Adafruit_HX8357(tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc, 136 | int8_t cs = -1, int8_t rst = -1, int8_t rd = -1); 137 | ~Adafruit_HX8357(void); 138 | 139 | void begin(uint32_t freq = 0), setRotation(uint8_t r), 140 | invertDisplay(boolean i), 141 | setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 142 | 143 | private: 144 | uint8_t displayType; // HX8357D vs HX8357B 145 | }; 146 | 147 | #endif // _ADAFRUIT_HX8357_H 148 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit HX8357 Arduino Library [![Build Status](https://github.com/adafruit/Adafruit_HX8357_Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_HX8357_Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_HX8357_Library/html/index.html) 2 | 3 | This is a library for the Adafruit HX8357 display products 4 | 5 | This library works with the Adafruit 3.5" Breakout 6 | * http://www.adafruit.com/products/2050 7 | And the 3.5" TFT FeatherWing 8 | * https://www.adafruit.com/product/3651 9 | 10 | Check out the links above for our tutorials and wiring diagrams. 11 | These displays use SPI to communicate, 4 or 5 pins are required 12 | to interface (RST is optional). 13 | 14 | Adafruit invests time and resources providing this open source code, 15 | please support Adafruit and open-source hardware by purchasing 16 | products from Adafruit! 17 | 18 | Written by Limor Fried/Ladyada for Adafruit Industries. 19 | MIT license, all text above must be included in any redistribution 20 | 21 | Recent Arduino IDE releases include the Library Manager for easy installation. Otherwise, to download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_HX8357. Confirm that the Adafruit_HX8357 folder contains Adafruit_HX8357.cpp and Adafruit_HX8357.h. Place the Adafruit_HX8357 library folder your ArduinoSketchFolder/Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE. 22 | 23 | Also requires the Adafruit_GFX library for Arduino. 24 | -------------------------------------------------------------------------------- /examples/bitmapdraw_featherwing/.leonardo.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/bitmapdraw_featherwing/.mega2560.test.skip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_HX8357_Library/bca58c0024f64e48e7c6a623e3cd8147ec19e10e/examples/bitmapdraw_featherwing/.mega2560.test.skip -------------------------------------------------------------------------------- /examples/bitmapdraw_featherwing/.qtpy_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/bitmapdraw_featherwing/.trinket_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/bitmapdraw_featherwing/bitmapdraw_featherwing.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our library for the Adafruit HX8357D FeatherWing 3 | ----> http://www.adafruit.com/products/3651 4 | 5 | Check out the links above for our tutorials and wiring diagrams 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface (RST is optional) 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. 13 | MIT license, all text above must be included in any redistribution 14 | ****************************************************/ 15 | 16 | #include // Core graphics library 17 | #include 18 | #include // Image-reading functions 19 | 20 | // If using the rev 1 with STMPE resistive touch screen controller uncomment this line: 21 | //#include 22 | // If using the rev 2 with TSC2007, uncomment this line: 23 | #include 24 | 25 | #ifdef ESP8266 26 | #define STMPE_CS 16 27 | #define TFT_CS 0 28 | #define TFT_DC 15 29 | #define SD_CS 2 30 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) 31 | #define STMPE_CS 8 32 | #define TFT_CS 9 33 | #define TFT_DC 10 34 | #define SD_CS 7 35 | #elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3) 36 | #define STMPE_CS 32 37 | #define TFT_CS 15 38 | #define TFT_DC 33 39 | #define SD_CS 14 40 | #elif defined(TEENSYDUINO) 41 | #define TFT_DC 10 42 | #define TFT_CS 4 43 | #define STMPE_CS 3 44 | #define SD_CS 8 45 | #elif defined(ARDUINO_STM32_FEATHER) 46 | #define TFT_DC PB4 47 | #define TFT_CS PA15 48 | #define STMPE_CS PC7 49 | #define SD_CS PC5 50 | #elif defined(ARDUINO_NRF52832_FEATHER) /* BSP 0.6.5 and higher! */ 51 | #define TFT_DC 11 52 | #define TFT_CS 31 53 | #define STMPE_CS 30 54 | #define SD_CS 27 55 | #elif defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR) 56 | #define TFT_DC P5_4 57 | #define TFT_CS P5_3 58 | #define STMPE_CS P3_3 59 | #define SD_CS P3_2 60 | #else 61 | // Anything else, defaults! 62 | #define STMPE_CS 6 63 | #define TFT_CS 9 64 | #define TFT_DC 10 65 | #define SD_CS 5 66 | #endif 67 | 68 | SdFat SD; // SD card filesystem 69 | Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys 70 | 71 | Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC); 72 | 73 | #if defined(_ADAFRUIT_STMPE610H_) 74 | Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS); 75 | #elif defined(_ADAFRUIT_TSC2007_H) 76 | // If you're using the TSC2007 there is no CS pin needed, so instead its an IRQ! 77 | #define TSC_IRQ STMPE_CS 78 | Adafruit_TSC2007 ts = Adafruit_TSC2007(); // newer rev 2 touch contoller 79 | #else 80 | #error("You must have either STMPE or TSC2007 headers included!") 81 | #endif 82 | 83 | // This is calibration data for the raw touch data to the screen coordinates 84 | // For STMPE811/STMPE610 85 | #define STMPE_TS_MINX 3800 86 | #define STMPE_TS_MAXX 100 87 | #define STMPE_TS_MINY 100 88 | #define STMPE_TS_MAXY 3750 89 | // For TSC2007 90 | #define TSC_TS_MINX 300 91 | #define TSC_TS_MAXX 3800 92 | #define TSC_TS_MINY 185 93 | #define TSC_TS_MAXY 3700 94 | // we will assign the calibration values on init 95 | int16_t min_x, max_x, min_y, max_y; 96 | 97 | // Size of the color selection boxes and the paintbrush size 98 | #define BOXSIZE 40 99 | #define PENRADIUS 3 100 | int oldcolor, currentcolor; 101 | 102 | 103 | void setup() { 104 | Serial.begin(115200); 105 | //while (!Serial) delay(10); 106 | 107 | Serial.println("HX8357D Featherwing full control test!"); 108 | 109 | #if defined(_ADAFRUIT_STMPE610H_) 110 | if (!ts.begin()) { 111 | Serial.println("Couldn't start STMPE touchscreen controller"); 112 | while (1) delay(100); 113 | } 114 | min_x = STMPE_TS_MINX; max_x = STMPE_TS_MAXX; 115 | min_y = STMPE_TS_MINY; max_y = STMPE_TS_MAXY; 116 | #else 117 | if (! ts.begin(0x48)) { 118 | Serial.println("Couldn't start TSC2007 touchscreen controller"); 119 | while (1) delay(100); 120 | } 121 | min_x = TSC_TS_MINX; max_x = TSC_TS_MAXX; 122 | min_y = TSC_TS_MINY; max_y = TSC_TS_MAXY; 123 | pinMode(TSC_IRQ, INPUT); 124 | #endif 125 | Serial.println("Touchscreen started"); 126 | 127 | tft.begin(); 128 | tft.fillScreen(HX8357_BLUE); 129 | 130 | Serial.print("Initializing SD card..."); 131 | // SD card is pretty straightforward, a single call... 132 | if(!SD.begin(SD_CS, SD_SCK_MHZ(8))) { // ESP32 requires 25 MHz limit 133 | Serial.println(F("SD begin() failed")); 134 | while(1) delay(10); 135 | } 136 | Serial.println("OK!"); 137 | 138 | delay(1); // ESP8266 needs this 139 | 140 | reader.drawBMP("/adabot.bmp", tft, 0, 0); 141 | Serial.println("Done"); 142 | 143 | delay(1); // ESP8266 needs this 144 | 145 | // make the color selection boxes 146 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED); 147 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW); 148 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN); 149 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN); 150 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE); 151 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA); 152 | 153 | // select the current color 'red' 154 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 155 | currentcolor = HX8357_RED; 156 | } 157 | 158 | 159 | void loop(void) { 160 | #if defined(TSC_IRQ) 161 | if (digitalRead(TSC_IRQ)) { 162 | // IRQ pin is high, nothing to read! 163 | return; 164 | } 165 | #endif 166 | TS_Point p = ts.getPoint(); 167 | 168 | Serial.print("X = "); Serial.print(p.x); 169 | Serial.print("\tY = "); Serial.print(p.y); 170 | Serial.print("\tPressure = "); Serial.print(p.z); 171 | if (((p.x == 0) && (p.y == 0)) || (p.z < 10)) return; // no pressure, no touch 172 | 173 | // Scale from ~0->4000 to tft.width using the calibration #'s 174 | p.x = map(p.x, min_x, max_x, 0, tft.width()); 175 | p.y = map(p.y, min_y, max_y, 0, tft.height()); 176 | Serial.print(" -> "); Serial.print(p.x); Serial.print(", "); Serial.println(p.y); 177 | 178 | 179 | 180 | if (p.y < BOXSIZE) { 181 | oldcolor = currentcolor; 182 | 183 | if (p.x < BOXSIZE) { 184 | currentcolor = HX8357_RED; 185 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 186 | } else if (p.x < BOXSIZE*2) { 187 | currentcolor = HX8357_YELLOW; 188 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 189 | } else if (p.x < BOXSIZE*3) { 190 | currentcolor = HX8357_GREEN; 191 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 192 | } else if (p.x < BOXSIZE*4) { 193 | currentcolor = HX8357_CYAN; 194 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 195 | } else if (p.x < BOXSIZE*5) { 196 | currentcolor = HX8357_BLUE; 197 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 198 | } else if (p.x < BOXSIZE*6) { 199 | currentcolor = HX8357_MAGENTA; 200 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 201 | } 202 | 203 | if (oldcolor != currentcolor) { 204 | if (oldcolor == HX8357_RED) 205 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED); 206 | if (oldcolor == HX8357_YELLOW) 207 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW); 208 | if (oldcolor == HX8357_GREEN) 209 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN); 210 | if (oldcolor == HX8357_CYAN) 211 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN); 212 | if (oldcolor == HX8357_BLUE) 213 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE); 214 | if (oldcolor == HX8357_MAGENTA) 215 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA); 216 | } 217 | } 218 | 219 | if (((p.y-PENRADIUS) > 0) && ((p.y+PENRADIUS) < tft.height())) { 220 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 221 | } 222 | } -------------------------------------------------------------------------------- /examples/breakouttouchpaint/.esp8266.test.skip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_HX8357_Library/bca58c0024f64e48e7c6a623e3cd8147ec19e10e/examples/breakouttouchpaint/.esp8266.test.skip -------------------------------------------------------------------------------- /examples/breakouttouchpaint/breakouttouchpaint.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our touchscreen painting example for the Adafruit HX8357 Breakout 3 | ----> http://www.adafruit.com/products/2050 4 | 5 | Check out the links above for our tutorials and wiring diagrams 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface (RST is optional) 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. 13 | MIT license, all text above must be included in any redistribution 14 | ****************************************************/ 15 | 16 | /** NOT FOR USE WITH THE TOUCH SHIELD, ONLY FOR THE 3.5" BREAKOUT! **/ 17 | 18 | #include // Core graphics library 19 | #include 20 | #include "Adafruit_HX8357.h" 21 | #include "TouchScreen.h" 22 | 23 | // These are the four touchscreen analog pins 24 | #define YP A2 // must be an analog pin, use "An" notation! 25 | #define XM A3 // must be an analog pin, use "An" notation! 26 | #define YM 7 // can be a digital pin 27 | #define XP 8 // can be a digital pin 28 | 29 | // This is calibration data for the raw touch data to the screen coordinates 30 | #define TS_MINX 110 31 | #define TS_MINY 80 32 | #define TS_MAXX 900 33 | #define TS_MAXY 940 34 | 35 | #define MINPRESSURE 10 36 | #define MAXPRESSURE 1000 37 | 38 | // The display uses hardware SPI, plus #9 & #10 39 | #define TFT_RST -1 // dont use a reset pin, tie to arduino RST if you like 40 | #define TFT_DC 9 41 | #define TFT_CS 10 42 | 43 | Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST); 44 | 45 | // For better pressure precision, we need to know the resistance 46 | // between X+ and X- Use any multimeter to read it 47 | // For the one we're using, its 300 ohms across the X plate 48 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 49 | 50 | // Size of the color selection boxes and the paintbrush size 51 | #define BOXSIZE 40 52 | #define PENRADIUS 3 53 | int oldcolor, currentcolor; 54 | 55 | void setup(void) { 56 | while (!Serial); // used for leonardo debugging 57 | 58 | Serial.begin(115200); 59 | Serial.println(F("Touch Paint!")); 60 | 61 | tft.begin(); 62 | tft.fillScreen(HX8357_BLACK); 63 | 64 | // make the color selection boxes 65 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED); 66 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW); 67 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN); 68 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN); 69 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE); 70 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA); 71 | tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_BLACK); 72 | tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 73 | 74 | // select the current color 'red' 75 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 76 | currentcolor = HX8357_RED; 77 | } 78 | 79 | 80 | void loop() 81 | { 82 | // Retrieve a point 83 | TSPoint p = ts.getPoint(); 84 | 85 | // we have some minimum pressure we consider 'valid' 86 | // pressure of 0 means no pressing! 87 | if (p.z < MINPRESSURE || p.z > MAXPRESSURE) { 88 | return; 89 | } 90 | 91 | Serial.print("X = "); Serial.print(p.x); 92 | Serial.print("\tY = "); Serial.print(p.y); 93 | Serial.print("\tPressure = "); Serial.println(p.z); 94 | 95 | // Scale from ~0->1000 to tft.width using the calibration #'s 96 | p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width()); 97 | p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height()); 98 | 99 | 100 | /* 101 | Serial.print("("); Serial.print(p.x); 102 | Serial.print(", "); Serial.print(p.y); 103 | Serial.println(")"); 104 | */ 105 | 106 | if (p.y < BOXSIZE) { 107 | oldcolor = currentcolor; 108 | 109 | if (p.x < BOXSIZE) { 110 | currentcolor = HX8357_RED; 111 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 112 | } else if (p.x < BOXSIZE*2) { 113 | currentcolor = HX8357_YELLOW; 114 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 115 | } else if (p.x < BOXSIZE*3) { 116 | currentcolor = HX8357_GREEN; 117 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 118 | } else if (p.x < BOXSIZE*4) { 119 | currentcolor = HX8357_CYAN; 120 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 121 | } else if (p.x < BOXSIZE*5) { 122 | currentcolor = HX8357_BLUE; 123 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 124 | } else if (p.x < BOXSIZE*6) { 125 | currentcolor = HX8357_MAGENTA; 126 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 127 | } else if (p.x < BOXSIZE*7) { 128 | currentcolor = HX8357_WHITE; 129 | tft.drawRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_RED); 130 | } else if (p.x < BOXSIZE*8) { 131 | currentcolor = HX8357_BLACK; 132 | tft.drawRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 133 | } 134 | 135 | if (oldcolor != currentcolor) { 136 | if (oldcolor == HX8357_RED) 137 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED); 138 | if (oldcolor == HX8357_YELLOW) 139 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW); 140 | if (oldcolor == HX8357_GREEN) 141 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN); 142 | if (oldcolor == HX8357_CYAN) 143 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN); 144 | if (oldcolor == HX8357_BLUE) 145 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE); 146 | if (oldcolor == HX8357_MAGENTA) 147 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA); 148 | if (oldcolor == HX8357_WHITE) 149 | tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 150 | if (oldcolor == HX8357_BLACK) 151 | tft.fillRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, HX8357_BLACK); 152 | } 153 | } 154 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 155 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /examples/gfxbuttontest_featherwing/.mega2560.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/gfxbuttontest_featherwing/.qtpy_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/gfxbuttontest_featherwing/.trinket_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/gfxbuttontest_featherwing/gfxbuttontest_featherwing.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * gfxbuttontest_featherwing 3 | */ 4 | 5 | #include // Core graphics library 6 | #include 7 | 8 | // If using the rev 1 with STMPE resistive touch screen controller uncomment this line: 9 | //#include 10 | // If using the rev 2 with TSC2007, uncomment this line: 11 | #include 12 | 13 | #ifdef ESP8266 14 | #define STMPE_CS 16 15 | #define TFT_CS 0 16 | #define TFT_DC 15 17 | #define SD_CS 2 18 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32C6) 19 | #define STMPE_CS 6 20 | #define TFT_CS 7 21 | #define TFT_DC 8 22 | #define SD_CS 5 23 | #elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3) 24 | #define STMPE_CS 32 25 | #define TFT_CS 15 26 | #define TFT_DC 33 27 | #define SD_CS 14 28 | #elif defined(TEENSYDUINO) 29 | #define TFT_DC 10 30 | #define TFT_CS 4 31 | #define STMPE_CS 3 32 | #define SD_CS 8 33 | #elif defined(ARDUINO_STM32_FEATHER) 34 | #define TFT_DC PB4 35 | #define TFT_CS PA15 36 | #define STMPE_CS PC7 37 | #define SD_CS PC5 38 | #elif defined(ARDUINO_NRF52832_FEATHER) /* BSP 0.6.5 and higher! */ 39 | #define TFT_DC 11 40 | #define TFT_CS 31 41 | #define STMPE_CS 30 42 | #define SD_CS 27 43 | #elif defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR) 44 | #define TFT_DC P5_4 45 | #define TFT_CS P5_3 46 | #define STMPE_CS P3_3 47 | #define SD_CS P3_2 48 | #else 49 | // Anything else, defaults! 50 | #define STMPE_CS 6 51 | #define TFT_CS 9 52 | #define TFT_DC 10 53 | #define SD_CS 5 54 | #endif 55 | 56 | 57 | 58 | #define TFT_RST -1 59 | 60 | 61 | // Use hardware SPI and the above for CS/DC 62 | Adafruit_HX8357 tft = Adafruit_HX8357( TFT_CS, TFT_DC, TFT_RST); 63 | 64 | #if defined(_ADAFRUIT_STMPE610H_) 65 | Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS); 66 | #elif defined(_ADAFRUIT_TSC2007_H) 67 | // If you're using the TSC2007 there is no CS pin needed, so instead its an IRQ! 68 | #define TSC_IRQ STMPE_CS 69 | Adafruit_TSC2007 ts = Adafruit_TSC2007(); // newer rev 2 touch contoller 70 | #else 71 | #error("You must have either STMPE or TSC2007 headers included!") 72 | #endif 73 | 74 | // This is calibration data for the raw touch data to the screen coordinates 75 | // For STMPE811/STMPE610 76 | #define STMPE_TS_MINX 3800 77 | #define STMPE_TS_MAXX 100 78 | #define STMPE_TS_MINY 100 79 | #define STMPE_TS_MAXY 3750 80 | // For TSC2007 81 | #define TSC_TS_MINX 300 82 | #define TSC_TS_MAXX 3800 83 | #define TSC_TS_MINY 185 84 | #define TSC_TS_MAXY 3700 85 | // we will assign the calibration values on init 86 | int16_t min_x, max_x, min_y, max_y; 87 | 88 | 89 | // Redefine original colors, add additional colors to match those available with the ILI9341 library 90 | #define HX8357_BLACK 0x0000 ///< 0, 0, 0 91 | #define HX8357_NAVY 0x000F ///< 0, 0, 123 92 | #define HX8357_DARKGREEN 0x03E0 ///< 0, 125, 0 93 | #define HX8357_DARKCYAN 0x03EF ///< 0, 125, 123 94 | #define HX8357_MAROON 0x7800 ///< 123, 0, 0 95 | #define HX8357_PURPLE 0x780F ///< 123, 0, 123 96 | #define HX8357_OLIVE 0x7BE0 ///< 123, 125, 0 97 | #define HX8357_LIGHTGREY 0xC618 ///< 198, 195, 198 98 | #define HX8357_DARKGREY 0x7BEF ///< 123, 125, 123 99 | #define HX8357_BLUE 0x001F ///< 0, 0, 255 100 | #define HX8357_GREEN 0x07E0 ///< 0, 255, 0 101 | #define HX8357_CYAN 0x07FF ///< 0, 255, 255 102 | #define HX8357_RED 0xF800 ///< 255, 0, 0 103 | #define HX8357_MAGENTA 0xF81F ///< 255, 0, 255 104 | #define HX8357_YELLOW 0xFFE0 ///< 255, 255, 0 105 | #define HX8357_WHITE 0xFFFF ///< 255, 255, 255 106 | #define HX8357_ORANGE 0xFD20 ///< 255, 165, 0 107 | #define HX8357_GREENYELLOW 0xAFE5 ///< 173, 255, 41 108 | #define HX8357_PINK 0xFC18 ///< 255, 130, 198 109 | 110 | // UI Buttondetails 111 | #define BUTTON_X 40 112 | #define BUTTON_Y 40 113 | #define BUTTON_W 80 114 | #define BUTTON_H 80 115 | #define BUTTON_TEXTSIZE 2 116 | #define DISPLAY_XOFFSET 80 117 | #define DISPLAY_TEXTOFFSET 90 118 | #define DISPLAY_YOFFSET 0 119 | 120 | enum ButtonName { 121 | BTN_UP, 122 | BTN_SELECT, 123 | BTN_DOWN, 124 | BTN_RETURN 125 | }; 126 | 127 | #define MENU1_BTN_CNT 4 128 | Adafruit_GFX_Button Menu1Buttons[MENU1_BTN_CNT]; 129 | char Menu1Labels[MENU1_BTN_CNT][5] = {"Up", "Sel", "Down", "Ret"}; 130 | uint16_t Menu1Colors[MENU1_BTN_CNT] = {HX8357_DARKGREY, HX8357_DARKGREY, 131 | HX8357_DARKGREY, HX8357_DARKGREY}; 132 | 133 | #define MENU2_BTN_CNT 4 134 | Adafruit_GFX_Button Menu2Buttons[MENU2_BTN_CNT]; 135 | char Menu2Labels[MENU2_BTN_CNT][5] = {"Up", "Sel", "Down", "Ret"}; 136 | uint16_t Menu2Colors[MENU2_BTN_CNT] = {HX8357_BLUE, HX8357_BLUE, 137 | HX8357_BLUE, HX8357_BLUE}; 138 | 139 | int textSize = 2; 140 | int textColorIndex = 0; 141 | uint16_t textColor[7] = { 142 | HX8357_WHITE, 143 | HX8357_RED, 144 | HX8357_GREEN, 145 | HX8357_BLUE, 146 | HX8357_CYAN, 147 | HX8357_MAGENTA, 148 | HX8357_YELLOW 149 | }; 150 | 151 | //------------------------------------------------------------------------- 152 | void setTextColorIndex(int updown) { 153 | textColorIndex += updown; 154 | if (textColorIndex > 6) 155 | textColorIndex = 0; 156 | else if (textColorIndex < 0) 157 | textColorIndex = 6; 158 | tft.setTextColor(textColor[textColorIndex]); 159 | } 160 | 161 | //------------------------------------------------------------------------- 162 | void setTextSizeIndex(int updown) { 163 | textSize += updown; 164 | if (textSize > 3) 165 | textSize = 1; 166 | else if (textSize < 1) 167 | textSize = 3; 168 | tft.setTextSize(textSize); 169 | } 170 | 171 | //------------------------------------------------------------------------- 172 | bool initializeButtons( 173 | Adafruit_GFX_Button menuButtons[], 174 | uint16_t menuColors[], 175 | char menuLabels[][5], 176 | int menuButtonCount) { 177 | tft.fillScreen(HX8357_BLACK); 178 | 179 | for (uint8_t row=0; row "); Serial.print(p.x); Serial.print(", "); Serial.println(p.y); 278 | 279 | // go thru all the buttons, checking if they were pressed 280 | for (uint8_t b=0; b= 0 && btn < MENU2_BTN_CNT) 323 | { 324 | Serial.print("btn = "); Serial.println(btn); 325 | } 326 | 327 | switch (btn) 328 | { 329 | case BTN_UP: 330 | msg = "Menu 2 Up button "; 331 | Serial.println(msg); 332 | setTextColorIndex(1); 333 | tftCenterPrint(msg); 334 | break; 335 | 336 | case BTN_SELECT: 337 | msg = "Menu 2 Select Button "; 338 | Serial.println(msg); 339 | setTextColorIndex(0); 340 | tftCenterPrint(msg); 341 | break; 342 | 343 | case BTN_DOWN: 344 | msg = "Menu 2 Down Button "; 345 | Serial.println(msg); 346 | setTextColorIndex(-1); 347 | tftCenterPrint(msg); 348 | break; 349 | 350 | case BTN_RETURN: 351 | msg = "Menu 2 Ret Button "; 352 | Serial.println(msg); 353 | Serial.println("Exiting Menu2, Returing to Menu1"); 354 | 355 | exitLoop = true; 356 | break; 357 | 358 | default: 359 | break; 360 | } 361 | } 362 | } 363 | 364 | //-------------------------------------------------------------------------------- 365 | void processMenu1() { 366 | String msg = ""; 367 | 368 | int btn = tftButtonRelease(Menu1Buttons, MENU1_BTN_CNT); 369 | if (btn >= 0 && btn < MENU1_BTN_CNT) 370 | { 371 | Serial.print("btn = "); Serial.println(btn); 372 | } 373 | 374 | switch (btn) 375 | { 376 | case BTN_UP: 377 | msg = "Menu 1 Up Button "; 378 | Serial.println(msg); 379 | tft.fillRect(DISPLAY_XOFFSET,DISPLAY_YOFFSET, tft.width(), tft.height(), HX8357_BLACK); 380 | setTextColorIndex(0); 381 | setTextSizeIndex(1); 382 | tftCenterPrint(msg); 383 | break; 384 | 385 | case BTN_SELECT: 386 | msg = "Menu 1 Select Button"; 387 | Serial.println(msg); 388 | processMenu2(); 389 | 390 | initializeButtons(Menu1Buttons, Menu1Colors, Menu1Labels, MENU1_BTN_CNT); 391 | 392 | msg = "Returned from Menu 2"; 393 | Serial.println(msg); 394 | setTextColorIndex(0); 395 | setTextSizeIndex(0); 396 | tftCenterPrint(msg); 397 | break; 398 | 399 | case BTN_DOWN: 400 | msg = "Menu 1 Down Button "; 401 | Serial.println(msg); 402 | tft.fillRect(DISPLAY_XOFFSET,DISPLAY_YOFFSET, tft.width(), tft.height(), HX8357_BLACK); 403 | setTextColorIndex(0); 404 | setTextSizeIndex(-1); 405 | tftCenterPrint(msg); 406 | break; 407 | 408 | case BTN_RETURN: 409 | msg = "Menu 1 Ret Button "; 410 | Serial.println(msg); 411 | tftCenterPrint(msg); 412 | break; 413 | 414 | default: 415 | break; 416 | } 417 | } 418 | 419 | //-------------------------------------------------------------------------------- 420 | void loop() { 421 | processMenu1(); 422 | } -------------------------------------------------------------------------------- /examples/graphicstest/graphicstest.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our library for the Adafruit HX8357D Breakout 3 | ----> http://www.adafruit.com/products/2050 4 | 5 | Check out the links above for our tutorials and wiring diagrams 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface (RST is optional) 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. 13 | MIT license, all text above must be included in any redistribution 14 | ****************************************************/ 15 | 16 | #include 17 | #include "Adafruit_GFX.h" 18 | #include "Adafruit_HX8357.h" 19 | 20 | // These are 'flexible' lines that can be changed 21 | #define TFT_CS 10 22 | #define TFT_DC 9 23 | #define TFT_RST 8 // RST can be set to -1 if you tie it to Arduino's reset 24 | 25 | // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC 26 | Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST); 27 | 28 | // SoftSPI - note that on some processors this might be *faster* than hardware SPI! 29 | //Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO); 30 | 31 | 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | Serial.println("HX8357D Test!"); 36 | 37 | tft.begin(); 38 | 39 | // read diagnostics (optional but can help debug problems) 40 | uint8_t x = tft.readcommand8(HX8357_RDPOWMODE); 41 | Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX); 42 | x = tft.readcommand8(HX8357_RDMADCTL); 43 | Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX); 44 | x = tft.readcommand8(HX8357_RDCOLMOD); 45 | Serial.print("Pixel Format: 0x"); Serial.println(x, HEX); 46 | x = tft.readcommand8(HX8357_RDDIM); 47 | Serial.print("Image Format: 0x"); Serial.println(x, HEX); 48 | x = tft.readcommand8(HX8357_RDDSDR); 49 | Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 50 | 51 | Serial.println(F("Benchmark Time (microseconds)")); 52 | 53 | tft.setRotation(1); 54 | 55 | Serial.print(F("Text ")); 56 | Serial.println(testText()); 57 | delay(500); 58 | 59 | Serial.print(F("Lines ")); 60 | Serial.println(testLines(HX8357_CYAN)); 61 | delay(500); 62 | 63 | Serial.print(F("Rectangles (outline) ")); 64 | Serial.println(testRects(HX8357_GREEN)); 65 | delay(500); 66 | 67 | tft.fillScreen(HX8357_BLACK); 68 | Serial.print(F("Circles (outline) ")); 69 | Serial.println(testCircles(10, HX8357_RED)); 70 | delay(500); 71 | 72 | 73 | Serial.print(F("Triangles (outline) ")); 74 | Serial.println(testTriangles()); 75 | delay(500); 76 | 77 | Serial.print(F("Triangles (filled) ")); 78 | Serial.println(testFilledTriangles()); 79 | delay(500); 80 | 81 | 82 | Serial.print(F("Rounded rects (outline) ")); 83 | Serial.println(testRoundRects()); 84 | delay(500); 85 | 86 | Serial.print(F("Rounded rects (filled) ")); 87 | Serial.println(testFilledRoundRects()); 88 | delay(500); 89 | 90 | Serial.println(F("Done!")); 91 | } 92 | 93 | 94 | void loop(void) { 95 | for(uint8_t rotation=0; rotation<4; rotation++) { 96 | tft.setRotation(rotation); 97 | testText(); 98 | delay(1000); 99 | } 100 | } 101 | 102 | unsigned long testFillScreen() { 103 | unsigned long start = micros(); 104 | tft.fillScreen(HX8357_RED); 105 | tft.fillScreen(HX8357_GREEN); 106 | tft.fillScreen(HX8357_BLUE); 107 | tft.fillScreen(HX8357_WHITE); 108 | return micros() - start; 109 | } 110 | 111 | 112 | unsigned long testText() { 113 | tft.fillScreen(HX8357_BLACK); 114 | unsigned long start = micros(); 115 | tft.setCursor(0, 0); 116 | tft.setTextColor(HX8357_WHITE); tft.setTextSize(1); 117 | tft.println("Hello World!"); 118 | tft.setTextColor(HX8357_YELLOW); tft.setTextSize(2); 119 | tft.println(1234.56); 120 | tft.setTextColor(HX8357_RED); tft.setTextSize(3); 121 | tft.println(0xDEADBEEF, HEX); 122 | tft.println(); 123 | tft.setTextColor(HX8357_GREEN); 124 | tft.setTextSize(5); 125 | tft.println("Groop"); 126 | tft.setTextSize(2); 127 | tft.println("I implore thee,"); 128 | tft.setTextSize(1); 129 | tft.println("my foonting turlingdromes."); 130 | tft.println("And hooptiously drangle me"); 131 | tft.println("with crinkly bindlewurdles,"); 132 | tft.println("Or I will rend thee"); 133 | tft.println("in the gobberwarts"); 134 | tft.println("with my blurglecruncheon,"); 135 | tft.println("see if I don't!"); 136 | 137 | tft.setTextColor(HX8357_WHITE); 138 | tft.println(F("Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?'")); 139 | 140 | tft.println(F("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.")); 141 | 142 | tft.println(F("There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.")); 143 | 144 | tft.println(F("In another moment down went Alice after it, never once considering how in the world she was to get out again.")); 145 | 146 | tft.println(F("The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well.")); 147 | 148 | tft.println(F("Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it.")); 149 | 150 | return micros() - start; 151 | } 152 | 153 | unsigned long testLines(uint16_t color) { 154 | unsigned long start; 155 | int x1, y1, x2, y2, 156 | w = tft.width(), 157 | h = tft.height(); 158 | 159 | tft.fillScreen(HX8357_BLACK); 160 | 161 | x1 = y1 = 0; 162 | y2 = h - 1; 163 | start = micros(); 164 | for(x2=0; x20; i-=6) { 209 | i2 = i / 2; 210 | start = micros(); 211 | tft.fillRect(cx-i2, cy-i2, i, i, color1); 212 | t += micros() - start; 213 | // Outlines are not included in timing results 214 | tft.drawRect(cx-i2, cy-i2, i, i, color2); 215 | } 216 | 217 | return t; 218 | } 219 | 220 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 221 | unsigned long start; 222 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 223 | 224 | tft.fillScreen(HX8357_BLACK); 225 | start = micros(); 226 | for(x=radius; x10; i-=5) { 280 | start = micros(); 281 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 282 | tft.color565(0, i, i)); 283 | t += micros() - start; 284 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 285 | tft.color565(i, i, 0)); 286 | } 287 | 288 | return t; 289 | } 290 | 291 | unsigned long testRoundRects() { 292 | unsigned long start; 293 | int w, i, i2, 294 | cx = tft.width() / 2 , 295 | cy = tft.height() / 2 ; 296 | 297 | tft.fillScreen(HX8357_BLACK); 298 | w = min(tft.width(), tft.height()); 299 | start = micros(); 300 | for(i=0; i25; i-=6) { 317 | i2 = i / 2; 318 | tft.fillRoundRect(cx-i2, cy-i2, i-20, i-20, i/8, tft.color565(100, i/2, 100)); 319 | } 320 | 321 | return micros() - start; 322 | } 323 | -------------------------------------------------------------------------------- /examples/graphicstest_featherwing/.mega2560.test.skip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_HX8357_Library/bca58c0024f64e48e7c6a623e3cd8147ec19e10e/examples/graphicstest_featherwing/.mega2560.test.skip -------------------------------------------------------------------------------- /examples/graphicstest_featherwing/.qtpy_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/graphicstest_featherwing/.trinket_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/graphicstest_featherwing/graphicstest_featherwing.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our library for the Adafruit 3.5" TFT (HX8357) FeatherWing 3 | ----> http://www.adafruit.com/products/3651 4 | 5 | Check out the links above for our tutorials and wiring diagrams 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface (RST is optional) 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. 13 | MIT license, all text above must be included in any redistribution 14 | ****************************************************/ 15 | 16 | #include 17 | #include "Adafruit_GFX.h" 18 | #include "Adafruit_HX8357.h" 19 | 20 | #ifdef ESP8266 21 | #define TFT_CS 0 22 | #define TFT_DC 15 23 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32C6) 24 | #define TFT_CS 7 25 | #define TFT_DC 8 26 | #elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3) 27 | #define TFT_CS 15 28 | #define TFT_DC 33 29 | #elif defined(TEENSYDUINO) 30 | #define TFT_DC 10 31 | #define TFT_CS 4 32 | #elif defined(ARDUINO_STM32_FEATHER) 33 | #define TFT_DC PB4 34 | #define TFT_CS PA15 35 | #elif defined(ARDUINO_NRF52832_FEATHER) /* BSP 0.6.5 and higher! */ 36 | #define TFT_DC 11 37 | #define TFT_CS 31 38 | #elif defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR) 39 | #define TFT_DC P5_4 40 | #define TFT_CS P5_3 41 | #else 42 | // Anything else, defaults! 43 | #define TFT_CS 9 44 | #define TFT_DC 10 45 | #endif 46 | 47 | 48 | #define TFT_RST -1 49 | 50 | // Use hardware SPI and the above for CS/DC 51 | Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST); 52 | 53 | 54 | void setup() { 55 | Serial.begin(115200); 56 | Serial.println("3.5\" HX8357D FeatherWing Test!"); 57 | 58 | tft.begin(); 59 | 60 | // read diagnostics (optional but can help debug problems) 61 | uint8_t x = tft.readcommand8(HX8357_RDPOWMODE); 62 | Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX); 63 | x = tft.readcommand8(HX8357_RDMADCTL); 64 | Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX); 65 | x = tft.readcommand8(HX8357_RDCOLMOD); 66 | Serial.print("Pixel Format: 0x"); Serial.println(x, HEX); 67 | x = tft.readcommand8(HX8357_RDDIM); 68 | Serial.print("Image Format: 0x"); Serial.println(x, HEX); 69 | x = tft.readcommand8(HX8357_RDDSDR); 70 | Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 71 | 72 | Serial.println(F("Benchmark Time (microseconds)")); 73 | 74 | tft.setRotation(1); 75 | 76 | Serial.print(F("Text ")); 77 | Serial.println(testText()); 78 | delay(500); 79 | 80 | Serial.print(F("Lines ")); 81 | Serial.println(testLines(HX8357_CYAN)); 82 | delay(500); 83 | 84 | Serial.print(F("Rectangles (outline) ")); 85 | Serial.println(testRects(HX8357_GREEN)); 86 | delay(500); 87 | 88 | tft.fillScreen(HX8357_BLACK); 89 | Serial.print(F("Circles (outline) ")); 90 | Serial.println(testCircles(10, HX8357_RED)); 91 | delay(500); 92 | 93 | 94 | Serial.print(F("Triangles (outline) ")); 95 | Serial.println(testTriangles()); 96 | delay(500); 97 | 98 | Serial.print(F("Triangles (filled) ")); 99 | Serial.println(testFilledTriangles()); 100 | delay(500); 101 | 102 | 103 | Serial.print(F("Rounded rects (outline) ")); 104 | Serial.println(testRoundRects()); 105 | delay(500); 106 | 107 | Serial.print(F("Rounded rects (filled) ")); 108 | Serial.println(testFilledRoundRects()); 109 | delay(500); 110 | 111 | Serial.println(F("Done!")); 112 | } 113 | 114 | 115 | void loop(void) { 116 | for(uint8_t rotation=0; rotation<4; rotation++) { 117 | tft.setRotation(rotation); 118 | testText(); 119 | delay(1000); 120 | } 121 | } 122 | 123 | unsigned long testFillScreen() { 124 | unsigned long start = micros(); 125 | tft.fillScreen(HX8357_RED); 126 | tft.fillScreen(HX8357_GREEN); 127 | tft.fillScreen(HX8357_BLUE); 128 | tft.fillScreen(HX8357_WHITE); 129 | return micros() - start; 130 | } 131 | 132 | 133 | unsigned long testText() { 134 | tft.fillScreen(HX8357_BLACK); 135 | unsigned long start = micros(); 136 | tft.setCursor(0, 0); 137 | tft.setTextColor(HX8357_WHITE); tft.setTextSize(1); 138 | tft.println("Hello World!"); 139 | tft.setTextColor(HX8357_YELLOW); tft.setTextSize(2); 140 | tft.println(1234.56); 141 | tft.setTextColor(HX8357_RED); tft.setTextSize(3); 142 | tft.println(0xDEADBEEF, HEX); 143 | tft.println(); 144 | tft.setTextColor(HX8357_GREEN); 145 | tft.setTextSize(5); 146 | tft.println("Groop"); 147 | tft.setTextSize(2); 148 | tft.println("I implore thee,"); 149 | tft.setTextSize(1); 150 | tft.println("my foonting turlingdromes."); 151 | tft.println("And hooptiously drangle me"); 152 | tft.println("with crinkly bindlewurdles,"); 153 | tft.println("Or I will rend thee"); 154 | tft.println("in the gobberwarts"); 155 | tft.println("with my blurglecruncheon,"); 156 | tft.println("see if I don't!"); 157 | 158 | tft.setTextColor(HX8357_WHITE); 159 | tft.println(F("Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?'")); 160 | 161 | tft.println(F("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.")); 162 | 163 | tft.println(F("There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.")); 164 | 165 | tft.println(F("In another moment down went Alice after it, never once considering how in the world she was to get out again.")); 166 | 167 | tft.println(F("The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well.")); 168 | 169 | tft.println(F("Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it.")); 170 | 171 | return micros() - start; 172 | } 173 | 174 | unsigned long testLines(uint16_t color) { 175 | unsigned long start; 176 | int x1, y1, x2, y2, 177 | w = tft.width(), 178 | h = tft.height(); 179 | 180 | tft.fillScreen(HX8357_BLACK); 181 | 182 | x1 = y1 = 0; 183 | y2 = h - 1; 184 | start = micros(); 185 | for(x2=0; x20; i-=6) { 230 | i2 = i / 2; 231 | start = micros(); 232 | tft.fillRect(cx-i2, cy-i2, i, i, color1); 233 | t += micros() - start; 234 | // Outlines are not included in timing results 235 | tft.drawRect(cx-i2, cy-i2, i, i, color2); 236 | } 237 | 238 | return t; 239 | } 240 | 241 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 242 | unsigned long start; 243 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 244 | 245 | tft.fillScreen(HX8357_BLACK); 246 | start = micros(); 247 | for(x=radius; x10; i-=5) { 301 | start = micros(); 302 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 303 | tft.color565(0, i, i)); 304 | t += micros() - start; 305 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 306 | tft.color565(i, i, 0)); 307 | } 308 | 309 | return t; 310 | } 311 | 312 | unsigned long testRoundRects() { 313 | unsigned long start; 314 | int w, i, i2, 315 | cx = tft.width() / 2 , 316 | cy = tft.height() / 2 ; 317 | 318 | tft.fillScreen(HX8357_BLACK); 319 | w = min(tft.width(), tft.height()); 320 | start = micros(); 321 | for(i=0; i25; i-=6) { 338 | i2 = i / 2; 339 | tft.fillRoundRect(cx-i2, cy-i2, i-20, i-20, i/8, tft.color565(100, i/2, 100)); 340 | } 341 | 342 | return micros() - start; 343 | } -------------------------------------------------------------------------------- /examples/touchpaint_featherwing/.mega2560.test.skip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_HX8357_Library/bca58c0024f64e48e7c6a623e3cd8147ec19e10e/examples/touchpaint_featherwing/.mega2560.test.skip -------------------------------------------------------------------------------- /examples/touchpaint_featherwing/.qtpy_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/touchpaint_featherwing/.trinket_m0.test.skip: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/touchpaint_featherwing/touchpaint_featherwing.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our library for the Adafruit HX8357D Featherwing 3 | ----> http://www.adafruit.com/products/2050 4 | 5 | Check out the links above for our tutorials and wiring diagrams 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface (RST is optional) 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. 13 | MIT license, all text above must be included in any redistribution 14 | ****************************************************/ 15 | 16 | #include // Core graphics library 17 | #include 18 | 19 | // If using the rev 1 with STMPE resistive touch screen controller uncomment this line: 20 | //#include 21 | // If using the rev 2 with TSC2007, uncomment this line: 22 | #include 23 | 24 | #ifdef ESP8266 25 | #define STMPE_CS 16 26 | #define TFT_CS 0 27 | #define TFT_DC 15 28 | #define SD_CS 2 29 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32C6) 30 | #define STMPE_CS 6 31 | #define TFT_CS 7 32 | #define TFT_DC 8 33 | #define SD_CS 5 34 | #elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3) 35 | #define STMPE_CS 32 36 | #define TFT_CS 15 37 | #define TFT_DC 33 38 | #define SD_CS 14 39 | #elif defined(TEENSYDUINO) 40 | #define TFT_DC 10 41 | #define TFT_CS 4 42 | #define STMPE_CS 3 43 | #define SD_CS 8 44 | #elif defined(ARDUINO_STM32_FEATHER) 45 | #define TFT_DC PB4 46 | #define TFT_CS PA15 47 | #define STMPE_CS PC7 48 | #define SD_CS PC5 49 | #elif defined(ARDUINO_NRF52832_FEATHER) /* BSP 0.6.5 and higher! */ 50 | #define TFT_DC 11 51 | #define TFT_CS 31 52 | #define STMPE_CS 30 53 | #define SD_CS 27 54 | #elif defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR) 55 | #define TFT_DC P5_4 56 | #define TFT_CS P5_3 57 | #define STMPE_CS P3_3 58 | #define SD_CS P3_2 59 | #else 60 | // Anything else, defaults! 61 | #define STMPE_CS 6 62 | #define TFT_CS 9 63 | #define TFT_DC 10 64 | #define SD_CS 5 65 | #endif 66 | 67 | #define TFT_RST -1 68 | 69 | // Init screen on hardware SPI, HX8357D type: 70 | Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST); 71 | 72 | #if defined(_ADAFRUIT_STMPE610H_) 73 | Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS); 74 | #elif defined(_ADAFRUIT_TSC2007_H) 75 | // If you're using the TSC2007 there is no CS pin needed, so instead its an IRQ! 76 | #define TSC_IRQ STMPE_CS 77 | Adafruit_TSC2007 ts = Adafruit_TSC2007(); // newer rev 2 touch contoller 78 | #else 79 | #error("You must have either STMPE or TSC2007 headers included!") 80 | #endif 81 | 82 | // This is calibration data for the raw touch data to the screen coordinates 83 | // For STMPE811/STMPE610 84 | #define STMPE_TS_MINX 3800 85 | #define STMPE_TS_MAXX 100 86 | #define STMPE_TS_MINY 100 87 | #define STMPE_TS_MAXY 3750 88 | // For TSC2007 89 | #define TSC_TS_MINX 300 90 | #define TSC_TS_MAXX 3800 91 | #define TSC_TS_MINY 185 92 | #define TSC_TS_MAXY 3700 93 | // we will assign the calibration values on init 94 | int16_t min_x, max_x, min_y, max_y; 95 | 96 | // Size of the color selection boxes and the paintbrush size 97 | #define BOXSIZE 40 98 | #define PENRADIUS 3 99 | uint16_t oldcolor, currentcolor; 100 | 101 | 102 | void setup() { 103 | Serial.begin(115200); 104 | //while (!Serial) delay(10); 105 | 106 | Serial.println("HX8357D Featherwing touch test!"); 107 | 108 | #if defined(_ADAFRUIT_STMPE610H_) 109 | if (!ts.begin()) { 110 | Serial.println("Couldn't start STMPE touchscreen controller"); 111 | while (1) delay(100); 112 | } 113 | min_x = STMPE_TS_MINX; max_x = STMPE_TS_MAXX; 114 | min_y = STMPE_TS_MINY; max_y = STMPE_TS_MAXY; 115 | #else 116 | if (! ts.begin(0x48, &Wire)) { 117 | Serial.println("Couldn't start TSC2007 touchscreen controller"); 118 | while (1) delay(100); 119 | } 120 | min_x = TSC_TS_MINX; max_x = TSC_TS_MAXX; 121 | min_y = TSC_TS_MINY; max_y = TSC_TS_MAXY; 122 | pinMode(TSC_IRQ, INPUT); 123 | #endif 124 | 125 | Serial.println("Touchscreen started"); 126 | 127 | tft.begin(); 128 | tft.fillScreen(HX8357_BLACK); 129 | // make the color selection boxes 130 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED); 131 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW); 132 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN); 133 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN); 134 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE); 135 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA); 136 | tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_BLACK); 137 | tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 138 | 139 | // select the current color 'red' 140 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 141 | currentcolor = HX8357_RED; 142 | } 143 | 144 | 145 | void loop(void) { 146 | #if defined(TSC_IRQ) 147 | if (digitalRead(TSC_IRQ)) { 148 | // IRQ pin is high, nothing to read! 149 | return; 150 | } 151 | #endif 152 | 153 | TS_Point p = ts.getPoint(); 154 | 155 | Serial.print("X = "); Serial.print(p.x); 156 | Serial.print("\tY = "); Serial.print(p.y); 157 | Serial.print("\tPressure = "); Serial.print(p.z); 158 | if (((p.x == 0) && (p.y == 0)) || (p.z < 10)) return; // no pressure, no touch 159 | 160 | // Scale from ~0->4000 to tft.width using the calibration #'s 161 | p.x = map(p.x, min_x, max_x, 0, tft.width()); 162 | p.y = map(p.y, min_y, max_y, 0, tft.height()); 163 | Serial.print(" -> "); Serial.print(p.x); Serial.print(", "); Serial.println(p.y); 164 | 165 | if (p.y < BOXSIZE) { 166 | oldcolor = currentcolor; 167 | 168 | if (p.x < BOXSIZE) { 169 | currentcolor = HX8357_RED; 170 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 171 | } else if (p.x < BOXSIZE*2) { 172 | currentcolor = HX8357_YELLOW; 173 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 174 | } else if (p.x < BOXSIZE*3) { 175 | currentcolor = HX8357_GREEN; 176 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 177 | } else if (p.x < BOXSIZE*4) { 178 | currentcolor = HX8357_CYAN; 179 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 180 | } else if (p.x < BOXSIZE*5) { 181 | currentcolor = HX8357_BLUE; 182 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 183 | } else if (p.x < BOXSIZE*6) { 184 | currentcolor = HX8357_MAGENTA; 185 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 186 | } else if (p.x < BOXSIZE*7) { 187 | currentcolor = HX8357_WHITE; 188 | tft.drawRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_RED); 189 | } else if (p.x < BOXSIZE*8) { 190 | currentcolor = HX8357_BLACK; 191 | tft.drawRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 192 | } 193 | 194 | 195 | if (oldcolor != currentcolor) { 196 | if (oldcolor == HX8357_RED) 197 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED); 198 | if (oldcolor == HX8357_YELLOW) 199 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW); 200 | if (oldcolor == HX8357_GREEN) 201 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN); 202 | if (oldcolor == HX8357_CYAN) 203 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN); 204 | if (oldcolor == HX8357_BLUE) 205 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE); 206 | if (oldcolor == HX8357_MAGENTA) 207 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA); 208 | if (oldcolor == HX8357_WHITE) 209 | tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_WHITE); 210 | if (oldcolor == HX8357_BLACK) 211 | tft.fillRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, HX8357_BLACK); 212 | } 213 | } 214 | 215 | if (((p.y-PENRADIUS) > 0) && ((p.y+PENRADIUS) < tft.height())) { 216 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 217 | } 218 | } -------------------------------------------------------------------------------- /jumpers.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_HX8357_Library/bca58c0024f64e48e7c6a623e3cd8147ec19e10e/jumpers.bmp -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit HX8357 Library 2 | version=1.1.20 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Adafruit HX8357 3.5" display library. 6 | paragraph=Adafruit HX8357 3.5" display library. 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit_HX8357_Library 9 | architectures=* 10 | depends=Adafruit STMPE610, Adafruit GFX Library, Adafruit TouchScreen, SD, Adafruit TSC2007, Adafruit ImageReader Library 11 | --------------------------------------------------------------------------------