├── .github └── workflows │ └── main.yml ├── Adafruit_ILI9341.cpp ├── Adafruit_ILI9341.h ├── README.txt ├── examples ├── avr │ ├── breakouttouchpaint │ │ └── breakouttouchpaint.ino │ ├── graphicstest │ │ └── graphicstest.ino │ ├── onoffbutton │ │ └── onoffbutton.ino │ ├── onoffbutton_breakout │ │ └── onoffbutton_breakout.ino │ ├── spitftbitmap │ │ └── spitftbitmap.ino │ └── touchpaint │ │ └── touchpaint.ino └── esp │ └── graphicstest_esp │ └── graphicstest.ino ├── library.properties └── travis └── common.sh /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | schedule: 4 | - cron: '0 0 * * 5' 5 | push: 6 | branches: [ master ] 7 | pull_request: 8 | branches: [ master ] 9 | release: 10 | types: [ published, created, edited ] 11 | 12 | # Allows you to run this workflow manually from the Actions tab 13 | workflow_dispatch: 14 | 15 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 16 | jobs: 17 | 18 | prepare_example_json: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | 23 | - name: generate examples 24 | id: set-matrix 25 | run: | 26 | source $GITHUB_WORKSPACE/travis/common.sh 27 | cd $GITHUB_WORKSPACE 28 | echo -en "::set-output name=matrix::" 29 | echo -en "[" 30 | 31 | get_sketches_json_matrix arduino $GITHUB_WORKSPACE/examples/esp esp8266 1.8.13 esp8266com:esp8266:generic:xtal=80,eesz=1M,FlashMode=qio,FlashFreq=80 32 | echo -en "," 33 | 34 | get_sketches_json_matrix arduino $GITHUB_WORKSPACE/examples/esp esp32 1.8.13 espressif:esp32:esp32:FlashFreq=80 35 | 36 | echo -en "]" 37 | outputs: 38 | matrix: ${{ steps.set-matrix.outputs.matrix }} 39 | 40 | prepare_ide: 41 | runs-on: ubuntu-latest 42 | strategy: 43 | fail-fast: false 44 | matrix: 45 | IDE_VERSION: [ 1.8.13 ] 46 | env: 47 | IDE_VERSION: ${{ matrix.IDE_VERSION }} 48 | 49 | steps: 50 | - uses: actions/checkout@v2 51 | 52 | - name: Get Date 53 | id: get-date 54 | run: | 55 | echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")" 56 | shell: bash 57 | 58 | - uses: actions/cache@v2 59 | id: cache_all 60 | with: 61 | path: | 62 | /home/runner/arduino_ide 63 | /home/runner/Arduino 64 | key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ matrix.IDE_VERSION }} 65 | 66 | - name: download IDE 67 | if: steps.cache_all.outputs.cache-hit != 'true' 68 | run: | 69 | wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz -q 70 | tar xf arduino-$IDE_VERSION-linux64.tar.xz 71 | mv arduino-$IDE_VERSION $HOME/arduino_ide 72 | 73 | - name: download Adafruit-GFX-Library 74 | if: steps.cache_all.outputs.cache-hit != 'true' 75 | run: | 76 | source $GITHUB_WORKSPACE/travis/common.sh 77 | clone_library https://github.com/adafruit/Adafruit-GFX-Library 78 | 79 | - name: download Adafruit_BusIO 80 | if: steps.cache_all.outputs.cache-hit != 'true' 81 | run: | 82 | source $GITHUB_WORKSPACE/travis/common.sh 83 | clone_library https://github.com/adafruit/Adafruit_BusIO.git 84 | 85 | - name: download esp8266 86 | if: steps.cache_all.outputs.cache-hit != 'true' 87 | run: | 88 | source $GITHUB_WORKSPACE/travis/common.sh 89 | get_core esp8266 90 | 91 | - name: download esp32 92 | if: steps.cache_all.outputs.cache-hit != 'true' && matrix.IDE_VERSION != '1.6.13' 93 | run: | 94 | source $GITHUB_WORKSPACE/travis/common.sh 95 | get_core esp32 96 | 97 | build: 98 | needs: [prepare_ide, prepare_example_json] 99 | runs-on: ubuntu-latest 100 | strategy: 101 | fail-fast: false 102 | matrix: 103 | include: ${{ fromJson(needs.prepare_example_json.outputs.matrix) }} 104 | env: 105 | CPU: ${{ matrix.cpu }} 106 | BOARD: ${{ matrix.board }} 107 | IDE_VERSION: ${{ matrix.ideversion }} 108 | SKETCH: ${{ matrix.sketch }} 109 | 110 | # Steps represent a sequence of tasks that will be executed as part of the job 111 | steps: 112 | - uses: actions/checkout@v2 113 | 114 | - name: install libgtk2.0-0 115 | run: | 116 | sudo apt-get install -y libgtk2.0-0 117 | 118 | - name: Get Date 119 | id: get-date 120 | run: | 121 | echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")" 122 | shell: bash 123 | 124 | - uses: actions/cache@v2 125 | id: cache_all 126 | with: 127 | path: | 128 | /home/runner/arduino_ide 129 | /home/runner/Arduino 130 | key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ matrix.ideversion }} 131 | 132 | - name: install python serial 133 | if: matrix.cpu == 'esp32' 134 | run: | 135 | sudo pip3 install pyserial 136 | sudo pip install pyserial 137 | # sudo apt install python-is-python3 138 | 139 | - name: start DISPLAY 140 | run: | 141 | /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 142 | export DISPLAY=:1.0 143 | sleep 3 144 | 145 | - name: test IDE 146 | run: | 147 | export PATH="$HOME/arduino_ide:$PATH" 148 | which arduino 149 | 150 | - name: copy code 151 | run: | 152 | mkdir -p $HOME/Arduino/libraries/ 153 | cp -r $GITHUB_WORKSPACE $HOME/Arduino/libraries/Adafruit_ILI9341 154 | 155 | - name: config IDE 156 | run: | 157 | export DISPLAY=:1.0 158 | export PATH="$HOME/arduino_ide:$PATH" 159 | arduino --board $BOARD --save-prefs 160 | arduino --get-pref sketchbook.path 161 | arduino --pref update.check=false 162 | 163 | - name: build example 164 | timeout-minutes: 20 165 | run: | 166 | export DISPLAY=:1.0 167 | export PATH="$HOME/arduino_ide:$PATH" 168 | source $GITHUB_WORKSPACE/travis/common.sh 169 | cd $GITHUB_WORKSPACE 170 | build_sketch arduino $SKETCH 171 | 172 | done: 173 | needs: [prepare_ide, prepare_example_json, build] 174 | runs-on: ubuntu-latest 175 | steps: 176 | - name: Done 177 | run: | 178 | echo DONE -------------------------------------------------------------------------------- /Adafruit_ILI9341.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our library for the Adafruit ILI9341 Breakout and Shield 3 | ----> http://www.adafruit.com/products/1651 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 | Modified 09 May 2015 by Markus Sattler - rewrite the code add ESP8266 support and many optimizations now 220% fastet (320% total) 16 | ****************************************************/ 17 | 18 | #include "Adafruit_ILI9341.h" 19 | 20 | #include 21 | #include "pins_arduino.h" 22 | #include "wiring_private.h" 23 | #include 24 | 25 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 26 | #define hwSPI true 27 | #endif 28 | 29 | #define writeCmdDataTmp(cmd, ...) { \ 30 | const uint8_t tmp##cmd##_[] = { __VA_ARGS__ }; \ 31 | writeCmdData(cmd, (uint8_t *) &tmp##cmd##_[0], sizeof(tmp##cmd##_)); \ 32 | } 33 | 34 | 35 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 36 | // Constructor when using software SPI. All output pins are configurable. 37 | Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t mosi, 38 | int8_t sclk, int8_t rst, int8_t miso) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) { 39 | _cs = cs; 40 | _dc = dc; 41 | _mosi = mosi; 42 | _miso = miso; 43 | _sclk = sclk; 44 | _rst = rst; 45 | hwSPI = false; 46 | } 47 | #endif 48 | 49 | // Constructor when using hardware SPI. Faster, but must use SPI pins 50 | // specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.) 51 | #if defined(ILI9341_USE_HW_CS) || defined(ILI9341_USE_NO_CS) 52 | Adafruit_ILI9341::Adafruit_ILI9341(int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) { 53 | _dc = dc; 54 | _rst = rst; 55 | hwSPI = true; 56 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 57 | _dcMask = digitalPinToBitMask(_dc); 58 | _rstMask = digitalPinToBitMask(_rst); 59 | #else 60 | _mosi = _sclk = 0; 61 | #endif 62 | } 63 | #else 64 | Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) { 65 | _cs = cs; 66 | _dc = dc; 67 | _rst = rst; 68 | #if defined(ESP8266) 69 | _csMask = digitalPinToBitMask(_cs); 70 | _dcMask = digitalPinToBitMask(_dc); 71 | _rstMask = digitalPinToBitMask(_rst); 72 | #elif !defined(ESP32) && !defined(ESP31B) 73 | hwSPI = true; 74 | _mosi = _sclk = 0; 75 | #endif 76 | } 77 | #endif 78 | 79 | 80 | #if defined(ESP8266) 81 | void Adafruit_ILI9341::spiwrite16(uint16_t c) { 82 | SPI.write16(c, true); 83 | } 84 | #elif defined(ESP32) || defined(ESP31B) 85 | void Adafruit_ILI9341::spiwrite16(uint16_t c) { 86 | SPI.write16(c); 87 | } 88 | #endif 89 | 90 | void Adafruit_ILI9341::spiwrite(uint8_t c) { 91 | 92 | //Serial.print("0x"); Serial.print(c, HEX); Serial.print(", "); 93 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 94 | if (hwSPI) { 95 | #endif 96 | #if defined (__AVR__) 97 | uint8_t backupSPCR = SPCR; 98 | SPCR = mySPCR; 99 | SPDR = c; 100 | while(!(SPSR & _BV(SPIF))); 101 | SPCR = backupSPCR; 102 | #elif defined(TEENSYDUINO) || defined(ESP8266) || defined(ESP32) || defined(ESP31B) 103 | SPI.write(c); 104 | #elif defined (__arm__) 105 | SPI.setClockDivider(11); // 8-ish MHz (full! speed!) 106 | SPI.setBitOrder(MSBFIRST); 107 | SPI.setDataMode(SPI_MODE0); 108 | SPI.transfer(c); 109 | #endif 110 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 111 | } else { 112 | // Fast SPI bitbang swiped from LPD8806 library 113 | for(uint8_t bit = 0x80; bit; bit >>= 1) { 114 | if(c & bit) { 115 | //digitalWrite(_mosi, HIGH); 116 | *mosiport |= mosipinmask; 117 | } else { 118 | //digitalWrite(_mosi, LOW); 119 | *mosiport &= ~mosipinmask; 120 | } 121 | //digitalWrite(_sclk, HIGH); 122 | *clkport |= clkpinmask; 123 | //digitalWrite(_sclk, LOW); 124 | *clkport &= ~clkpinmask; 125 | } 126 | } 127 | #endif 128 | } 129 | 130 | void Adafruit_ILI9341::spiwriteBytes(uint8_t * data, uint32_t size) { 131 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 132 | SPI.writeBytes(data, size); 133 | #else 134 | while(size--) { 135 | spiwrite(*data); 136 | data++; 137 | } 138 | #endif 139 | } 140 | 141 | void Adafruit_ILI9341::spiwritePattern(uint8_t * data, uint8_t size, uint32_t repeat) { 142 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 143 | SPI.writePattern(data, size, repeat); 144 | #else 145 | uint8_t * ptr; 146 | uint8_t i; 147 | while(repeat--) { 148 | ptr = data; 149 | i = size; 150 | while(i--) { 151 | spiwrite(*ptr); 152 | ptr++; 153 | } 154 | } 155 | #endif 156 | } 157 | 158 | 159 | inline void Adafruit_ILI9341::spiCsLow(void) { 160 | #ifdef ILI9341_USE_DIGITAL_WRITE 161 | digitalWrite(_cs, LOW); 162 | #else 163 | #if defined(ESP8266) 164 | #if !defined(ILI9341_USE_HW_CS) && !defined(ILI9341_USE_NO_CS) 165 | GPOC = _csMask; 166 | #endif 167 | #else 168 | *csport &= ~cspinmask; 169 | #endif 170 | #endif 171 | } 172 | 173 | inline void Adafruit_ILI9341::spiCsHigh(void) { 174 | #ifdef ILI9341_USE_DIGITAL_WRITE 175 | digitalWrite(_cs, HIGH); 176 | #else 177 | #if defined(ESP8266) 178 | #if !defined(ILI9341_USE_HW_CS) && !defined(ILI9341_USE_NO_CS) 179 | GPOS = _csMask; 180 | #endif 181 | #else 182 | *csport |= cspinmask; 183 | #endif 184 | #endif 185 | } 186 | 187 | inline void Adafruit_ILI9341::spiDcLow(void){ 188 | #ifdef ILI9341_USE_DIGITAL_WRITE 189 | digitalWrite(_dc, LOW); 190 | #else 191 | #if defined(ESP8266) 192 | #ifndef USE_HW_CS 193 | GPOC = _dcMask; 194 | #endif 195 | #else 196 | *dcport &= ~dcpinmask; 197 | #endif 198 | #endif 199 | } 200 | 201 | inline void Adafruit_ILI9341::spiDcHigh(void) { 202 | #ifdef ILI9341_USE_DIGITAL_WRITE 203 | digitalWrite(_dc, HIGH); 204 | #else 205 | #if defined(ESP8266) 206 | GPOS = _dcMask; 207 | #else 208 | *dcport |= dcpinmask; 209 | #endif 210 | #endif 211 | } 212 | 213 | void Adafruit_ILI9341::writecommand(uint8_t c) { 214 | spiDcLow(); 215 | spiCsLow(); 216 | 217 | spiwrite(c); 218 | 219 | spiCsHigh(); 220 | } 221 | 222 | void Adafruit_ILI9341::writedata(uint8_t c) { 223 | spiDcHigh(); 224 | spiCsLow(); 225 | 226 | spiwrite(c); 227 | 228 | spiCsHigh(); 229 | } 230 | 231 | void Adafruit_ILI9341::writedata(uint8_t * data, uint8_t size) { 232 | spiDcHigh(); 233 | spiCsLow(); 234 | 235 | spiwriteBytes(data, size); 236 | 237 | spiCsHigh(); 238 | } 239 | 240 | void Adafruit_ILI9341::writeCmdData(uint8_t cmd, uint8_t * data, uint8_t size) { 241 | spiDcLow(); 242 | spiCsLow(); 243 | 244 | spiwrite(cmd); 245 | 246 | spiDcHigh(); 247 | 248 | spiwriteBytes(data, size); 249 | 250 | spiCsHigh(); 251 | } 252 | 253 | uint16_t Adafruit_ILI9341::getHeight(void) { 254 | return _height; 255 | } 256 | 257 | uint16_t Adafruit_ILI9341::getWidth(void){ 258 | return _width; 259 | } 260 | 261 | // If the SPI library has transaction support, these functions 262 | // establish settings and protect from interference from other 263 | // libraries. Otherwise, they simply do nothing. 264 | #ifdef SPI_HAS_TRANSACTION 265 | #ifndef ILI9341_SPEED 266 | #if defined(ESP8266) 267 | SPISettings spiSettings = SPISettings(ESP8266_CLOCK, MSBFIRST, SPI_MODE0); 268 | #else 269 | SPISettings spiSettings = SPISettings(8000000, MSBFIRST, SPI_MODE0); 270 | #endif 271 | #else 272 | SPISettings spiSettings = SPISettings(ILI9341_SPEED, MSBFIRST, SPI_MODE0); 273 | #endif 274 | static inline void spi_begin(void) __attribute__((always_inline)); 275 | static inline void spi_begin(void) { 276 | SPI.beginTransaction(spiSettings); 277 | } 278 | static inline void spi_end(void) __attribute__((always_inline)); 279 | static inline void spi_end(void) { 280 | SPI.endTransaction(); 281 | } 282 | #else 283 | #define spi_begin() 284 | #define spi_end() 285 | #endif 286 | 287 | // Rather than a bazillion writecommand() and writedata() calls, screen 288 | // initialization commands and arguments are organized in these tables 289 | // stored in PROGMEM. The table may look bulky, but that's mostly the 290 | // formatting -- storage-wise this is hundreds of bytes more compact 291 | // than the equivalent code. Companion function follows. 292 | #define DELAY 0x80 293 | 294 | 295 | // Companion code to the above tables. Reads and issues 296 | // a series of LCD commands stored in PROGMEM byte array. 297 | void Adafruit_ILI9341::commandList(uint8_t *addr) { 298 | 299 | uint8_t numCommands, numArgs; 300 | uint16_t ms; 301 | 302 | numCommands = pgm_read_byte(addr++); // Number of commands to follow 303 | while(numCommands--) { // For each command... 304 | writecommand(pgm_read_byte(addr++)); // Read, issue command 305 | numArgs = pgm_read_byte(addr++); // Number of args to follow 306 | ms = numArgs & DELAY; // If hibit set, delay follows args 307 | numArgs &= ~DELAY; // Mask out delay bit 308 | while(numArgs--) { // For each argument... 309 | writedata(pgm_read_byte(addr++)); // Read, issue argument 310 | } 311 | 312 | if(ms) { 313 | ms = pgm_read_byte(addr++); // Read post-command delay time (ms) 314 | if(ms == 255) ms = 500; // If 255, delay for 500 ms 315 | delay(ms); 316 | } 317 | } 318 | } 319 | 320 | 321 | void Adafruit_ILI9341::begin(void) { 322 | if (_rst > NOT_A_PIN) { 323 | pinMode(_rst, OUTPUT); 324 | digitalWrite(_rst, LOW); 325 | } 326 | 327 | pinMode(_dc, OUTPUT); 328 | #ifndef USE_HW_CS 329 | pinMode(_cs, OUTPUT); 330 | #endif 331 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 332 | #ifndef ILI9341_USE_DIGITAL_WRITE 333 | csport = portOutputRegister(digitalPinToPort(_cs)); 334 | cspinmask = digitalPinToBitMask(_cs); 335 | dcport = portOutputRegister(digitalPinToPort(_dc)); 336 | dcpinmask = digitalPinToBitMask(_dc); 337 | #endif 338 | if(hwSPI) { // Using hardware SPI 339 | #endif 340 | #if defined (__AVR__) 341 | SPI.begin(); 342 | SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) 343 | SPI.setBitOrder(MSBFIRST); 344 | SPI.setDataMode(SPI_MODE0); 345 | mySPCR = SPCR; 346 | #elif defined(TEENSYDUINO) 347 | SPI.begin(); 348 | SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) 349 | SPI.setBitOrder(MSBFIRST); 350 | SPI.setDataMode(SPI_MODE0); 351 | #elif defined (__arm__) 352 | SPI.begin(); 353 | SPI.setClockDivider(11); // 8-ish MHz (full! speed!) 354 | SPI.setBitOrder(MSBFIRST); 355 | SPI.setDataMode(SPI_MODE0); 356 | #elif defined(ESP8266) || defined(ESP32) || defined(ESP31B) 357 | SPI.begin(); 358 | #ifdef USE_HW_CS 359 | SPI.setHwCs(true); 360 | #endif 361 | #endif 362 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 363 | } else { 364 | pinMode(_sclk, OUTPUT); 365 | pinMode(_mosi, OUTPUT); 366 | pinMode(_miso, INPUT); 367 | clkport = portOutputRegister(digitalPinToPort(_sclk)); 368 | clkpinmask = digitalPinToBitMask(_sclk); 369 | mosiport = portOutputRegister(digitalPinToPort(_mosi)); 370 | mosipinmask = digitalPinToBitMask(_mosi); 371 | *clkport &= ~clkpinmask; 372 | *mosiport &= ~mosipinmask; 373 | } 374 | #endif 375 | // toggle RST low to reset 376 | if (_rst > NOT_A_PIN) { 377 | digitalWrite(_rst, HIGH); 378 | delay(5); 379 | digitalWrite(_rst, LOW); 380 | delay(20); 381 | digitalWrite(_rst, HIGH); 382 | delay(150); 383 | } 384 | 385 | /* 386 | uint8_t x = readcommand8(ILI9341_RDMODE); 387 | Serial.print("\nDisplay Power Mode: 0x"); Serial.println(x, HEX); 388 | x = readcommand8(ILI9341_RDMADCTL); 389 | Serial.print("\nMADCTL Mode: 0x"); Serial.println(x, HEX); 390 | x = readcommand8(ILI9341_RDPIXFMT); 391 | Serial.print("\nPixel Format: 0x"); Serial.println(x, HEX); 392 | x = readcommand8(ILI9341_RDIMGFMT); 393 | Serial.print("\nImage Format: 0x"); Serial.println(x, HEX); 394 | x = readcommand8(ILI9341_RDSELFDIAG); 395 | Serial.print("\nSelf Diagnostic: 0x"); Serial.println(x, HEX); 396 | */ 397 | //if(cmdList) commandList(cmdList); 398 | 399 | if (hwSPI) spi_begin(); 400 | 401 | writeCmdDataTmp(0xEF, 0x03, 0x80, 0x02); 402 | writeCmdDataTmp(0xCF, 0x00, 0XC1, 0X30); 403 | writeCmdDataTmp(0xED, 0x64, 0x03, 0X12, 0X81); 404 | writeCmdDataTmp(0xE8, 0x85, 0x00, 0x78); 405 | writeCmdDataTmp(0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02); 406 | writeCmdDataTmp(0xF7, 0x20); 407 | writeCmdDataTmp(0xEA, 0x00, 0x00); 408 | 409 | //Powercontrol 410 | //VRH[5:0] 411 | writeCmdDataTmp(ILI9341_PWCTR1, 0x23); 412 | 413 | //Powercontrol 414 | //SAP[2:0];BT[3:0] 415 | writeCmdDataTmp(ILI9341_PWCTR2, 0x10); 416 | 417 | //VCMcontrol 418 | writeCmdDataTmp(ILI9341_VMCTR1, 0x3e, 0x28); 419 | 420 | //VCMcontrol2 421 | writeCmdDataTmp(ILI9341_VMCTR2, 0x86); 422 | 423 | //MemoryAccessControl 424 | writeCmdDataTmp(ILI9341_MADCTL, 0x48); 425 | 426 | writeCmdDataTmp(ILI9341_PIXFMT, 0x55); 427 | writeCmdDataTmp(ILI9341_FRMCTR1, 0x00, 0x18); 428 | 429 | //DisplayFunctionControl 430 | writeCmdDataTmp(ILI9341_DFUNCTR, 0x08, 0x82, 0x27); 431 | 432 | //3GammaFunctionDisable 433 | writeCmdDataTmp(0xF2, 0x00); 434 | 435 | //Gammacurveselected 436 | writeCmdDataTmp(ILI9341_GAMMASET, 0x01); 437 | 438 | //SetGamma 439 | writeCmdDataTmp(ILI9341_GMCTRP1, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00); 440 | writeCmdDataTmp(ILI9341_GMCTRN1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F); 441 | 442 | writecommand(ILI9341_SLPOUT); //Exit Sleep 443 | if (hwSPI) spi_end(); 444 | delay(120); 445 | if (hwSPI) spi_begin(); 446 | writecommand(ILI9341_DISPON); //Display on 447 | if (hwSPI) spi_end(); 448 | 449 | } 450 | 451 | 452 | void Adafruit_ILI9341::area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { 453 | spiCsLow(); 454 | setAddrWindow_(x, y, x + w - 1, y + h - 1); 455 | } 456 | 457 | void Adafruit_ILI9341::area_update_data(uint8_t *data, uint32_t pixel){ 458 | spiwriteBytes(&data[0], (pixel*2)); 459 | } 460 | 461 | void Adafruit_ILI9341::area_update_end(void){ 462 | spiCsHigh(); 463 | } 464 | 465 | void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { 466 | spiCsLow(); 467 | setAddrWindow_(x0, y0, x1, y1); 468 | spiCsHigh(); 469 | } 470 | 471 | void Adafruit_ILI9341::setAddrWindow_(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { 472 | 473 | uint8_t buffC[] = { (uint8_t) (x0 >> 8), (uint8_t) x0, (uint8_t) (x1 >> 8), (uint8_t) x1 }; 474 | uint8_t buffP[] = { (uint8_t) (y0 >> 8), (uint8_t) y0, (uint8_t) (y1 >> 8), (uint8_t) y1 }; 475 | 476 | spiDcLow(); 477 | spiwrite(ILI9341_CASET); 478 | spiDcHigh(); 479 | spiwriteBytes(&buffC[0], sizeof(buffC)); 480 | 481 | spiDcLow(); 482 | spiwrite(ILI9341_PASET); 483 | spiDcHigh(); 484 | spiwriteBytes(&buffP[0], sizeof(buffP)); 485 | 486 | spiDcLow(); 487 | spiwrite(ILI9341_RAMWR); 488 | spiDcHigh(); 489 | 490 | } 491 | 492 | 493 | void Adafruit_ILI9341::pushColor(uint16_t color) { 494 | if (hwSPI) spi_begin(); 495 | 496 | spiDcHigh(); 497 | spiCsLow(); 498 | 499 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 500 | spiwrite16(color); 501 | #else 502 | spiwrite(color >> 8); 503 | spiwrite(color); 504 | #endif 505 | 506 | spiCsHigh(); 507 | 508 | if (hwSPI) spi_end(); 509 | } 510 | 511 | void Adafruit_ILI9341::drawPixel(int16_t x, int16_t y, uint16_t color) { 512 | 513 | if((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) { 514 | return; 515 | } 516 | 517 | if(hwSPI) { 518 | spi_begin(); 519 | } 520 | 521 | spiCsLow(); 522 | 523 | setAddrWindow_(x, y, x + 1, y + 1); 524 | 525 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 526 | spiwrite16(color); 527 | #else 528 | spiwrite(color >> 8); 529 | spiwrite(color); 530 | #endif 531 | 532 | spiCsHigh(); 533 | 534 | if(hwSPI) { 535 | spi_end(); 536 | } 537 | } 538 | 539 | 540 | void Adafruit_ILI9341::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { 541 | 542 | // Rudimentary clipping 543 | if((x >= _width) || (y >= _height)) return; 544 | if((y + h - 1) >= _height) h = _height - y; 545 | 546 | if(hwSPI) { 547 | spi_begin(); 548 | } 549 | 550 | spiCsLow(); 551 | 552 | setAddrWindow_(x, y, x, (y + h - 1)); 553 | 554 | uint8_t colorBin[] = { (uint8_t) (color >> 8), (uint8_t) color }; 555 | spiwritePattern(&colorBin[0], 2, h); 556 | 557 | spiCsHigh(); 558 | 559 | if(hwSPI) { 560 | spi_end(); 561 | } 562 | } 563 | 564 | void Adafruit_ILI9341::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { 565 | 566 | // Rudimentary clipping 567 | if((x >= _width) || (y >= _height)) return; 568 | if((x+w-1) >= _width) w = _width-x; 569 | 570 | if(hwSPI) { 571 | spi_begin(); 572 | } 573 | 574 | spiDcHigh(); 575 | spiCsLow(); 576 | 577 | setAddrWindow_(x, y, (x + w - 1), y); 578 | 579 | uint8_t colorBin[] = { (uint8_t) (color >> 8), (uint8_t) color }; 580 | spiwritePattern(&colorBin[0], 2, w); 581 | 582 | spiCsHigh(); 583 | 584 | if(hwSPI) { 585 | spi_end(); 586 | } 587 | } 588 | 589 | void Adafruit_ILI9341::fillScreen(uint16_t color) { 590 | fillRect(0, 0, _width, _height, color); 591 | } 592 | 593 | // fill a rectangle 594 | void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { 595 | 596 | // rudimentary clipping (drawChar w/big text requires this) 597 | if((x >= _width) || (y >= _height)) 598 | return; 599 | if((x + w - 1) >= _width) 600 | w = _width - x; 601 | if((y + h - 1) >= _height) 602 | h = _height - y; 603 | 604 | if(hwSPI) { 605 | spi_begin(); 606 | } 607 | 608 | spiCsLow(); 609 | 610 | setAddrWindow_(x, y, (x + w - 1), (y + h - 1)); 611 | 612 | uint8_t colorBin[] = { (uint8_t) (color >> 8), (uint8_t) color }; 613 | spiwritePattern(&colorBin[0], 2, (w * h)); 614 | 615 | spiCsHigh(); 616 | 617 | if(hwSPI) { 618 | spi_end(); 619 | } 620 | } 621 | 622 | 623 | // Pass 8-bit (each) R,G,B, get back 16-bit packed color 624 | uint16_t Adafruit_ILI9341::color565(uint8_t r, uint8_t g, uint8_t b) { 625 | return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); 626 | } 627 | 628 | 629 | #define MADCTL_MY 0x80 630 | #define MADCTL_MX 0x40 631 | #define MADCTL_MV 0x20 632 | #define MADCTL_ML 0x10 633 | #define MADCTL_RGB 0x00 634 | #define MADCTL_BGR 0x08 635 | #define MADCTL_MH 0x04 636 | 637 | void Adafruit_ILI9341::setRotation(uint8_t m) { 638 | 639 | if (hwSPI) spi_begin(); 640 | writecommand(ILI9341_MADCTL); 641 | rotation = m % 4; // can't be higher than 3 642 | switch (rotation) { 643 | case 0: 644 | writedata(MADCTL_MX | MADCTL_BGR); 645 | _width = ILI9341_TFTWIDTH; 646 | _height = ILI9341_TFTHEIGHT; 647 | break; 648 | case 1: 649 | writedata(MADCTL_MV | MADCTL_BGR); 650 | _width = ILI9341_TFTHEIGHT; 651 | _height = ILI9341_TFTWIDTH; 652 | break; 653 | case 2: 654 | writedata(MADCTL_MY | MADCTL_BGR); 655 | _width = ILI9341_TFTWIDTH; 656 | _height = ILI9341_TFTHEIGHT; 657 | break; 658 | case 3: 659 | writedata(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR); 660 | _width = ILI9341_TFTHEIGHT; 661 | _height = ILI9341_TFTWIDTH; 662 | break; 663 | } 664 | if (hwSPI) spi_end(); 665 | } 666 | 667 | 668 | void Adafruit_ILI9341::invertDisplay(boolean i) { 669 | if (hwSPI) spi_begin(); 670 | writecommand(i ? ILI9341_INVON : ILI9341_INVOFF); 671 | if (hwSPI) spi_end(); 672 | } 673 | 674 | 675 | ////////// stuff not actively being used, but kept for posterity 676 | 677 | 678 | uint8_t Adafruit_ILI9341::spiread(void) { 679 | uint8_t r = 0; 680 | 681 | if (hwSPI) { 682 | #if defined (__AVR__) 683 | uint8_t backupSPCR = SPCR; 684 | SPCR = mySPCR; 685 | SPDR = 0x00; 686 | while(!(SPSR & _BV(SPIF))); 687 | r = SPDR; 688 | SPCR = backupSPCR; 689 | #elif defined(TEENSYDUINO) 690 | r = SPI.transfer(0x00); 691 | #elif defined (__arm__) 692 | SPI.setClockDivider(11); // 8-ish MHz (full! speed!) 693 | SPI.setBitOrder(MSBFIRST); 694 | SPI.setDataMode(SPI_MODE0); 695 | r = SPI.transfer(0x00); 696 | #else 697 | r = SPI.transfer(0x00); 698 | #endif 699 | } else { 700 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 701 | for (uint8_t i=0; i<8; i++) { 702 | digitalWrite(_sclk, LOW); 703 | digitalWrite(_sclk, HIGH); 704 | r <<= 1; 705 | if (digitalRead(_miso)) 706 | r |= 0x1; 707 | } 708 | #endif 709 | } 710 | //Serial.print("read: 0x"); Serial.print(r, HEX); 711 | 712 | return r; 713 | } 714 | 715 | uint8_t Adafruit_ILI9341::readdata(void) { 716 | if(hwSPI) spi_begin(); 717 | spiCsLow(); 718 | spiDcLow(); 719 | uint8_t r = spiread(); 720 | spiCsHigh(); 721 | if(hwSPI) spi_end(); 722 | return r; 723 | } 724 | 725 | uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) { 726 | if(hwSPI) spi_begin(); 727 | 728 | spiCsLow(); 729 | spiDcLow(); 730 | 731 | spiwrite(0xD9); // woo sekret command? 732 | spiDcHigh(); 733 | spiwrite(0x10 + index); 734 | 735 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 736 | digitalWrite(_sclk, LOW); 737 | #endif 738 | 739 | spiDcLow(); 740 | spiwrite(c); 741 | 742 | spiDcHigh(); 743 | uint8_t r = spiread(); 744 | spiCsHigh(); 745 | 746 | if(hwSPI) spi_end(); 747 | return r; 748 | } 749 | 750 | /* 751 | 752 | uint16_t Adafruit_ILI9341::readcommand16(uint8_t c) { 753 | digitalWrite(_dc, LOW); 754 | if (_cs) 755 | digitalWrite(_cs, LOW); 756 | 757 | spiwrite(c); 758 | pinMode(_sid, INPUT); // input! 759 | uint16_t r = spiread(); 760 | r <<= 8; 761 | r |= spiread(); 762 | if (_cs) 763 | digitalWrite(_cs, HIGH); 764 | 765 | pinMode(_sid, OUTPUT); // back to output 766 | return r; 767 | } 768 | 769 | uint32_t Adafruit_ILI9341::readcommand32(uint8_t c) { 770 | digitalWrite(_dc, LOW); 771 | if (_cs) 772 | digitalWrite(_cs, LOW); 773 | spiwrite(c); 774 | pinMode(_sid, INPUT); // input! 775 | 776 | dummyclock(); 777 | dummyclock(); 778 | 779 | uint32_t r = spiread(); 780 | r <<= 8; 781 | r |= spiread(); 782 | r <<= 8; 783 | r |= spiread(); 784 | r <<= 8; 785 | r |= spiread(); 786 | if (_cs) 787 | digitalWrite(_cs, HIGH); 788 | 789 | pinMode(_sid, OUTPUT); // back to output 790 | return r; 791 | } 792 | 793 | */ 794 | -------------------------------------------------------------------------------- /Adafruit_ILI9341.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our library for the Adafruit ILI9341 Breakout and Shield 3 | ----> http://www.adafruit.com/products/1651 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 | #ifndef _ADAFRUIT_ILI9341H_ 17 | #define _ADAFRUIT_ILI9341H_ 18 | 19 | #if ARDUINO >= 100 20 | #include "Arduino.h" 21 | #include "Print.h" 22 | #else 23 | #include "WProgram.h" 24 | #endif 25 | #include 26 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 27 | #include 28 | #else 29 | #include 30 | #endif 31 | 32 | #define ILI9341_TFTWIDTH 240 33 | #define ILI9341_TFTHEIGHT 320 34 | 35 | #define ILI9341_NOP 0x00 36 | #define ILI9341_SWRESET 0x01 37 | #define ILI9341_RDDID 0x04 38 | #define ILI9341_RDDST 0x09 39 | 40 | #define ILI9341_SLPIN 0x10 41 | #define ILI9341_SLPOUT 0x11 42 | #define ILI9341_PTLON 0x12 43 | #define ILI9341_NORON 0x13 44 | 45 | #define ILI9341_RDMODE 0x0A 46 | #define ILI9341_RDMADCTL 0x0B 47 | #define ILI9341_RDPIXFMT 0x0C 48 | #define ILI9341_RDIMGFMT 0x0D 49 | #define ILI9341_RDSELFDIAG 0x0F 50 | 51 | #define ILI9341_INVOFF 0x20 52 | #define ILI9341_INVON 0x21 53 | #define ILI9341_GAMMASET 0x26 54 | #define ILI9341_DISPOFF 0x28 55 | #define ILI9341_DISPON 0x29 56 | 57 | #define ILI9341_CASET 0x2A 58 | #define ILI9341_PASET 0x2B 59 | #define ILI9341_RAMWR 0x2C 60 | #define ILI9341_RAMRD 0x2E 61 | 62 | #define ILI9341_PTLAR 0x30 63 | #define ILI9341_MADCTL 0x36 64 | #define ILI9341_PIXFMT 0x3A 65 | 66 | #define ILI9341_FRMCTR1 0xB1 67 | #define ILI9341_FRMCTR2 0xB2 68 | #define ILI9341_FRMCTR3 0xB3 69 | #define ILI9341_INVCTR 0xB4 70 | #define ILI9341_DFUNCTR 0xB6 71 | 72 | #define ILI9341_PWCTR1 0xC0 73 | #define ILI9341_PWCTR2 0xC1 74 | #define ILI9341_PWCTR3 0xC2 75 | #define ILI9341_PWCTR4 0xC3 76 | #define ILI9341_PWCTR5 0xC4 77 | #define ILI9341_VMCTR1 0xC5 78 | #define ILI9341_VMCTR2 0xC7 79 | 80 | #define ILI9341_RDID1 0xDA 81 | #define ILI9341_RDID2 0xDB 82 | #define ILI9341_RDID3 0xDC 83 | #define ILI9341_RDID4 0xDD 84 | 85 | #define ILI9341_GMCTRP1 0xE0 86 | #define ILI9341_GMCTRN1 0xE1 87 | /* 88 | #define ILI9341_PWCTR6 0xFC 89 | 90 | */ 91 | 92 | // Color definitions 93 | #define ILI9341_BLACK 0x0000 /* 0, 0, 0 */ 94 | #define ILI9341_NAVY 0x000F /* 0, 0, 128 */ 95 | #define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */ 96 | #define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */ 97 | #define ILI9341_MAROON 0x7800 /* 128, 0, 0 */ 98 | #define ILI9341_PURPLE 0x780F /* 128, 0, 128 */ 99 | #define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */ 100 | #define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */ 101 | #define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */ 102 | #define ILI9341_BLUE 0x001F /* 0, 0, 255 */ 103 | #define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */ 104 | #define ILI9341_LIGHTBLUE 0x061F /* 0, 192, 255 */ 105 | #define ILI9341_CYAN 0x07FF /* 0, 255, 255 */ 106 | #define ILI9341_RED 0xF800 /* 255, 0, 0 */ 107 | #define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */ 108 | #define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */ 109 | #define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */ 110 | #define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */ 111 | #define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ 112 | #define ILI9341_PINK 0xF81F 113 | 114 | //#define ILI9341_USE_DIGITAL_WRITE 115 | //#define ILI9341_USE_NO_CS 116 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 117 | //not working 118 | //#define ILI9341_USE_HW_CS 119 | #endif 120 | #if defined(ESP32) || defined(ESP31B) 121 | #define ILI9341_USE_DIGITAL_WRITE 122 | #endif 123 | class Adafruit_ILI9341 : public Adafruit_GFX { 124 | 125 | public: 126 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 127 | Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, 128 | int8_t _RST, int8_t _MISO); 129 | #endif 130 | #if defined(USE_HW_CS) || defined(USE_NO_CS) 131 | Adafruit_ILI9341(int8_t _DC, int8_t _RST = -1); 132 | #else 133 | Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1); 134 | #endif 135 | void begin(void), 136 | setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1), 137 | pushColor(uint16_t color), 138 | fillScreen(uint16_t color), 139 | drawPixel(int16_t x, int16_t y, uint16_t color), 140 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 141 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 142 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 143 | uint16_t color), 144 | setRotation(uint8_t r), 145 | invertDisplay(boolean i); 146 | uint16_t color565(uint8_t r, uint8_t g, uint8_t b); 147 | 148 | void commandList(uint8_t *addr); 149 | 150 | /* These are not for current use, 8-bit protocol only! */ 151 | uint8_t readdata(void), 152 | readcommand8(uint8_t reg, uint8_t index = 0); 153 | /* 154 | uint16_t readcommand16(uint8_t); 155 | uint32_t readcommand32(uint8_t); 156 | void dummyclock(void); 157 | */ 158 | 159 | void writecommand(uint8_t c); 160 | void writedata(uint8_t d); 161 | void writedata(uint8_t * data, uint8_t size); 162 | void writeCmdData(uint8_t cmd, uint8_t * data, uint8_t size); 163 | 164 | 165 | uint16_t getHeight(void); 166 | uint16_t getWidth(void); 167 | 168 | void area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h); 169 | void area_update_data(uint8_t *data, uint32_t pixel); 170 | void area_update_end(void); 171 | private: 172 | 173 | uint8_t spiread(void); 174 | 175 | 176 | #if defined(ESP8266) || defined(ESP32) || defined(ESP31B) 177 | inline void spiwrite(uint8_t data); 178 | inline void spiwrite16(uint16_t data); 179 | inline void spiwriteBytes(uint8_t * data, uint32_t size); 180 | inline void spiwritePattern(uint8_t * data, uint8_t size, uint32_t repeat); 181 | 182 | inline void setAddrWindow_(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); 183 | #else 184 | void spiwrite(uint8_t); 185 | void spiwrite16(uint16_t data); 186 | void spiwriteBytes(uint8_t * data, uint8_t size); 187 | void spiwritePattern(uint8_t * data, uint8_t size, uint8_t repeat); 188 | void setAddrWindow_(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); 189 | #endif 190 | 191 | inline void spiCsHigh(void); 192 | inline void spiCsLow(void); 193 | inline void spiDcHigh(void); 194 | inline void spiDcLow(void); 195 | 196 | uint8_t tabcolor; 197 | #if !defined(ESP8266) && !defined(ESP32) && !defined(ESP31B) 198 | boolean hwSPI; 199 | #endif 200 | #if defined (__AVR__) || defined(TEENSYDUINO) || defined(ESP32) || defined(ESP31B) 201 | uint8_t mySPCR; 202 | volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport; 203 | int8_t _cs, _dc, _rst, _mosi, _miso, _sclk; 204 | uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask; 205 | #elif defined (__arm__) 206 | volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport; 207 | uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk; 208 | uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask; 209 | #elif defined(ESP8266) 210 | #ifndef USE_HW_CS 211 | int8_t _cs; 212 | uint32_t _csMask; 213 | #endif 214 | int8_t _dc, _rst; 215 | uint32_t _dcMask, _rstMask; 216 | #endif 217 | }; 218 | 219 | #endif 220 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit ILI9341 display products [![Build Status](https://github.com/Links2004/Adafruit_ILI9341/workflows/CI/badge.svg?branch=master)](https://github.com/Links2004/Adafruit_ILI9341/actions?query=workflow%3ACI+branch%3Amaster) 2 | 3 | This library works with the Adafruit 2.8" Touch Shield V2 (SPI) 4 | ----> http://www.adafruit.com/products/1651 5 | 6 | Check out the links above for our tutorials and wiring diagrams. 7 | These displays use SPI to communicate, 4 or 5 pins are required 8 | to interface (RST is optional). 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 | MIT license, all text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_ILI9341. Check that the Adafruit_ILI9341 folder contains Adafruit_ILI9341.cpp and Adafruit_ILI9341. 18 | 19 | Place the Adafruit_ILI9341 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE 20 | 21 | Also requires the Adafruit_GFX library for Arduino. 22 | -------------------------------------------------------------------------------- /examples/avr/breakouttouchpaint/breakouttouchpaint.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our touchscreen painting example for the Adafruit ILI9341 Breakout 3 | ----> http://www.adafruit.com/products/1770 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 BREAKOUT! **/ 17 | 18 | #include // Core graphics library 19 | #include 20 | #include 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 5 // can be a digital pin 27 | #define XP 4 // can be a digital pin 28 | 29 | // This is calibration data for the raw touch data to the screen coordinates 30 | #define TS_MINX 150 31 | #define TS_MINY 120 32 | #define TS_MAXX 920 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_CS 10 40 | #define TFT_DC 9 41 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 42 | 43 | // For better pressure precision, we need to know the resistance 44 | // between X+ and X- Use any multimeter to read it 45 | // For the one we're using, its 300 ohms across the X plate 46 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 47 | 48 | // Size of the color selection boxes and the paintbrush size 49 | #define BOXSIZE 40 50 | #define PENRADIUS 3 51 | int oldcolor, currentcolor; 52 | 53 | void setup(void) { 54 | // while (!Serial); // used for leonardo debugging 55 | 56 | Serial.begin(9600); 57 | Serial.println(F("Touch Paint!")); 58 | 59 | tft.begin(); 60 | tft.fillScreen(ILI9341_BLACK); 61 | 62 | // make the color selection boxes 63 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); 64 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); 65 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); 66 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); 67 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); 68 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); 69 | 70 | // select the current color 'red' 71 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 72 | currentcolor = ILI9341_RED; 73 | } 74 | 75 | 76 | void loop() 77 | { 78 | // Retrieve a point 79 | TSPoint p = ts.getPoint(); 80 | 81 | /* 82 | Serial.print("X = "); Serial.print(p.x); 83 | Serial.print("\tY = "); Serial.print(p.y); 84 | Serial.print("\tPressure = "); Serial.println(p.z); 85 | */ 86 | 87 | // we have some minimum pressure we consider 'valid' 88 | // pressure of 0 means no pressing! 89 | if (p.z < MINPRESSURE || p.z > MAXPRESSURE) { 90 | return; 91 | } 92 | 93 | // Scale from ~0->1000 to tft.width using the calibration #'s 94 | p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width()); 95 | p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height()); 96 | 97 | /* 98 | Serial.print("("); Serial.print(p.x); 99 | Serial.print(", "); Serial.print(p.y); 100 | Serial.println(")"); 101 | */ 102 | 103 | 104 | if (p.y < BOXSIZE) { 105 | oldcolor = currentcolor; 106 | 107 | if (p.x < BOXSIZE) { 108 | currentcolor = ILI9341_RED; 109 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 110 | } else if (p.x < BOXSIZE*2) { 111 | currentcolor = ILI9341_YELLOW; 112 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 113 | } else if (p.x < BOXSIZE*3) { 114 | currentcolor = ILI9341_GREEN; 115 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 116 | } else if (p.x < BOXSIZE*4) { 117 | currentcolor = ILI9341_CYAN; 118 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 119 | } else if (p.x < BOXSIZE*5) { 120 | currentcolor = ILI9341_BLUE; 121 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 122 | } else if (p.x < BOXSIZE*6) { 123 | currentcolor = ILI9341_MAGENTA; 124 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 125 | } 126 | 127 | if (oldcolor != currentcolor) { 128 | if (oldcolor == ILI9341_RED) 129 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); 130 | if (oldcolor == ILI9341_YELLOW) 131 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); 132 | if (oldcolor == ILI9341_GREEN) 133 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); 134 | if (oldcolor == ILI9341_CYAN) 135 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); 136 | if (oldcolor == ILI9341_BLUE) 137 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); 138 | if (oldcolor == ILI9341_MAGENTA) 139 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); 140 | } 141 | } 142 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 143 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /examples/avr/graphicstest/graphicstest.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our GFX example for the Adafruit ILI9341 Breakout and Shield 3 | ----> http://www.adafruit.com/products/1651 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 | 17 | #include "SPI.h" 18 | #include "Adafruit_GFX.h" 19 | #include "Adafruit_ILI9341.h" 20 | 21 | // For the Adafruit shield, these are the default. 22 | #define TFT_DC 9 23 | #define TFT_CS 10 24 | 25 | // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC 26 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 27 | // If using the breakout, change pins as desired 28 | //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO); 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | Serial.println("ILI9341 Test!"); 33 | 34 | tft.begin(); 35 | 36 | // read diagnostics (optional but can help debug problems) 37 | uint8_t x = tft.readcommand8(ILI9341_RDMODE); 38 | Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX); 39 | x = tft.readcommand8(ILI9341_RDMADCTL); 40 | Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX); 41 | x = tft.readcommand8(ILI9341_RDPIXFMT); 42 | Serial.print("Pixel Format: 0x"); Serial.println(x, HEX); 43 | x = tft.readcommand8(ILI9341_RDIMGFMT); 44 | Serial.print("Image Format: 0x"); Serial.println(x, HEX); 45 | x = tft.readcommand8(ILI9341_RDSELFDIAG); 46 | Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 47 | 48 | Serial.println(F("Benchmark Time (microseconds)")); 49 | 50 | Serial.print(F("Screen fill ")); 51 | Serial.println(testFillScreen()); 52 | delay(500); 53 | 54 | Serial.print(F("Text ")); 55 | Serial.println(testText()); 56 | delay(3000); 57 | 58 | Serial.print(F("Lines ")); 59 | Serial.println(testLines(ILI9341_CYAN)); 60 | delay(500); 61 | 62 | Serial.print(F("Horiz/Vert Lines ")); 63 | Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE)); 64 | delay(500); 65 | 66 | Serial.print(F("Rectangles (outline) ")); 67 | Serial.println(testRects(ILI9341_GREEN)); 68 | delay(500); 69 | 70 | Serial.print(F("Rectangles (filled) ")); 71 | Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA)); 72 | delay(500); 73 | 74 | Serial.print(F("Circles (filled) ")); 75 | Serial.println(testFilledCircles(10, ILI9341_MAGENTA)); 76 | 77 | Serial.print(F("Circles (outline) ")); 78 | Serial.println(testCircles(10, ILI9341_WHITE)); 79 | delay(500); 80 | 81 | Serial.print(F("Triangles (outline) ")); 82 | Serial.println(testTriangles()); 83 | delay(500); 84 | 85 | Serial.print(F("Triangles (filled) ")); 86 | Serial.println(testFilledTriangles()); 87 | delay(500); 88 | 89 | Serial.print(F("Rounded rects (outline) ")); 90 | Serial.println(testRoundRects()); 91 | delay(500); 92 | 93 | Serial.print(F("Rounded rects (filled) ")); 94 | Serial.println(testFilledRoundRects()); 95 | delay(500); 96 | 97 | Serial.println(F("Done!")); 98 | 99 | } 100 | 101 | 102 | void loop(void) { 103 | for(uint8_t rotation=0; rotation<4; rotation++) { 104 | tft.setRotation(rotation); 105 | testText(); 106 | delay(1000); 107 | } 108 | } 109 | 110 | unsigned long testFillScreen() { 111 | unsigned long start = micros(); 112 | tft.fillScreen(ILI9341_BLACK); 113 | tft.fillScreen(ILI9341_RED); 114 | tft.fillScreen(ILI9341_GREEN); 115 | tft.fillScreen(ILI9341_BLUE); 116 | tft.fillScreen(ILI9341_BLACK); 117 | return micros() - start; 118 | } 119 | 120 | unsigned long testText() { 121 | tft.fillScreen(ILI9341_BLACK); 122 | unsigned long start = micros(); 123 | tft.setCursor(0, 0); 124 | tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); 125 | tft.println("Hello World!"); 126 | tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); 127 | tft.println(1234.56); 128 | tft.setTextColor(ILI9341_RED); tft.setTextSize(3); 129 | tft.println(0xDEADBEEF, HEX); 130 | tft.println(); 131 | tft.setTextColor(ILI9341_GREEN); 132 | tft.setTextSize(5); 133 | tft.println("Groop"); 134 | tft.setTextSize(2); 135 | tft.println("I implore thee,"); 136 | tft.setTextSize(1); 137 | tft.println("my foonting turlingdromes."); 138 | tft.println("And hooptiously drangle me"); 139 | tft.println("with crinkly bindlewurdles,"); 140 | tft.println("Or I will rend thee"); 141 | tft.println("in the gobberwarts"); 142 | tft.println("with my blurglecruncheon,"); 143 | tft.println("see if I don't!"); 144 | return micros() - start; 145 | } 146 | 147 | unsigned long testLines(uint16_t color) { 148 | unsigned long start, t; 149 | int x1, y1, x2, y2, 150 | w = tft.width(), 151 | h = tft.height(); 152 | 153 | tft.fillScreen(ILI9341_BLACK); 154 | 155 | x1 = y1 = 0; 156 | y2 = h - 1; 157 | start = micros(); 158 | for(x2=0; x20; i-=6) { 236 | i2 = i / 2; 237 | start = micros(); 238 | tft.fillRect(cx-i2, cy-i2, i, i, color1); 239 | t += micros() - start; 240 | // Outlines are not included in timing results 241 | tft.drawRect(cx-i2, cy-i2, i, i, color2); 242 | } 243 | 244 | return t; 245 | } 246 | 247 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 248 | unsigned long start; 249 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 250 | 251 | tft.fillScreen(ILI9341_BLACK); 252 | start = micros(); 253 | for(x=radius; x10; i-=5) { 307 | start = micros(); 308 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 309 | tft.color565(0, i, i)); 310 | t += micros() - start; 311 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 312 | tft.color565(i, i, 0)); 313 | } 314 | 315 | return t; 316 | } 317 | 318 | unsigned long testRoundRects() { 319 | unsigned long start; 320 | int w, i, i2, 321 | cx = tft.width() / 2 - 1, 322 | cy = tft.height() / 2 - 1; 323 | 324 | tft.fillScreen(ILI9341_BLACK); 325 | w = min(tft.width(), tft.height()); 326 | start = micros(); 327 | for(i=0; i20; i-=6) { 344 | i2 = i / 2; 345 | tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); 346 | } 347 | 348 | return micros() - start; 349 | } -------------------------------------------------------------------------------- /examples/avr/onoffbutton/onoffbutton.ino: -------------------------------------------------------------------------------- 1 | //This example implements a simple sliding On/Off button. The example 2 | // demonstrates drawing and touch operations. 3 | // 4 | //Thanks to Adafruit forums member Asteroid for the original sketch! 5 | // 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | // This is calibration data for the raw touch data to the screen coordinates 13 | #define TS_MINX 150 14 | #define TS_MINY 130 15 | #define TS_MAXX 3800 16 | #define TS_MAXY 4000 17 | 18 | #define STMPE_CS 8 19 | Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS); 20 | #define TFT_CS 10 21 | #define TFT_DC 9 22 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 23 | 24 | boolean RecordOn = false; 25 | 26 | #define FRAME_X 210 27 | #define FRAME_Y 180 28 | #define FRAME_W 100 29 | #define FRAME_H 50 30 | 31 | #define REDBUTTON_X FRAME_X 32 | #define REDBUTTON_Y FRAME_Y 33 | #define REDBUTTON_W (FRAME_W/2) 34 | #define REDBUTTON_H FRAME_H 35 | 36 | #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W) 37 | #define GREENBUTTON_Y FRAME_Y 38 | #define GREENBUTTON_W (FRAME_W/2) 39 | #define GREENBUTTON_H FRAME_H 40 | 41 | void drawFrame() 42 | { 43 | tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK); 44 | } 45 | 46 | void redBtn() 47 | { 48 | tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED); 49 | tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE); 50 | drawFrame(); 51 | tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2)); 52 | tft.setTextColor(ILI9341_WHITE); 53 | tft.setTextSize(2); 54 | tft.println("ON"); 55 | RecordOn = false; 56 | } 57 | 58 | void greenBtn() 59 | { 60 | tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN); 61 | tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE); 62 | drawFrame(); 63 | tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2)); 64 | tft.setTextColor(ILI9341_WHITE); 65 | tft.setTextSize(2); 66 | tft.println("OFF"); 67 | RecordOn = true; 68 | } 69 | 70 | void setup(void) 71 | { 72 | Serial.begin(9600); 73 | tft.begin(); 74 | if (!ts.begin()) { 75 | Serial.println("Unable to start touchscreen."); 76 | } 77 | else { 78 | Serial.println("Touchscreen started."); 79 | } 80 | 81 | tft.fillScreen(ILI9341_BLUE); 82 | // origin = left,top landscape (USB left upper) 83 | tft.setRotation(1); 84 | redBtn(); 85 | } 86 | 87 | void loop() 88 | { 89 | // See if there's any touch data for us 90 | if (!ts.bufferEmpty()) 91 | { 92 | // Retrieve a point 93 | TS_Point p = ts.getPoint(); 94 | // Scale using the calibration #'s 95 | // and rotate coordinate system 96 | p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height()); 97 | p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width()); 98 | int y = tft.height() - p.x; 99 | int x = p.y; 100 | 101 | if (RecordOn) 102 | { 103 | if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) { 104 | if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) { 105 | Serial.println("Red btn hit"); 106 | redBtn(); 107 | } 108 | } 109 | } 110 | else //Record is off (RecordOn == false) 111 | { 112 | if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) { 113 | if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) { 114 | Serial.println("Green btn hit"); 115 | greenBtn(); 116 | } 117 | } 118 | } 119 | 120 | Serial.println(RecordOn); 121 | } 122 | } 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /examples/avr/onoffbutton_breakout/onoffbutton_breakout.ino: -------------------------------------------------------------------------------- 1 | //This example implements a simple sliding On/Off button. The example 2 | // demonstrates drawing and touch operations. 3 | // 4 | //Thanks to Adafruit forums member Asteroid for the original sketch! 5 | // 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | //Touchscreen X+ X- Y+ Y- pins 13 | #define YP A3 // must be an analog pin, use "An" notation! 14 | #define XM A2 // must be an analog pin, use "An" notation! 15 | #define YM 5 // can be a digital pin 16 | #define XP 4 // can be a digital pin 17 | 18 | // This is calibration data for the raw touch data to the screen coordinates 19 | #define TS_MINX 150 20 | #define TS_MINY 120 21 | #define TS_MAXX 920 22 | #define TS_MAXY 940 23 | 24 | #define MINPRESSURE 10 25 | #define MAXPRESSURE 1000 26 | 27 | // For better pressure precision, we need to know the resistance 28 | // between X+ and X- Use any multimeter to read it 29 | // For the one we're using, its 300 ohms across the X plate 30 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 31 | 32 | 33 | #define TFT_CS 10 34 | #define TFT_DC 9 35 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 36 | 37 | boolean RecordOn = false; 38 | 39 | #define FRAME_X 210 40 | #define FRAME_Y 180 41 | #define FRAME_W 100 42 | #define FRAME_H 50 43 | 44 | #define REDBUTTON_X FRAME_X 45 | #define REDBUTTON_Y FRAME_Y 46 | #define REDBUTTON_W (FRAME_W/2) 47 | #define REDBUTTON_H FRAME_H 48 | 49 | #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W) 50 | #define GREENBUTTON_Y FRAME_Y 51 | #define GREENBUTTON_W (FRAME_W/2) 52 | #define GREENBUTTON_H FRAME_H 53 | 54 | void drawFrame() 55 | { 56 | tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK); 57 | } 58 | 59 | void redBtn() 60 | { 61 | tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED); 62 | tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE); 63 | drawFrame(); 64 | tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2)); 65 | tft.setTextColor(ILI9341_WHITE); 66 | tft.setTextSize(2); 67 | tft.println("ON"); 68 | RecordOn = false; 69 | } 70 | 71 | void greenBtn() 72 | { 73 | tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN); 74 | tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE); 75 | drawFrame(); 76 | tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2)); 77 | tft.setTextColor(ILI9341_WHITE); 78 | tft.setTextSize(2); 79 | tft.println("OFF"); 80 | RecordOn = true; 81 | } 82 | 83 | void setup(void) 84 | { 85 | Serial.begin(9600); 86 | tft.begin(); 87 | 88 | tft.fillScreen(ILI9341_BLUE); 89 | // origin = left,top landscape (USB left upper) 90 | tft.setRotation(1); 91 | redBtn(); 92 | } 93 | 94 | void loop() 95 | { 96 | // Retrieve a point 97 | TSPoint p = ts.getPoint(); 98 | 99 | // See if there's any touch data for us 100 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) 101 | { 102 | // Scale using the calibration #'s 103 | // and rotate coordinate system 104 | p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height()); 105 | p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width()); 106 | int y = tft.height() - p.x; 107 | int x = p.y; 108 | 109 | if (RecordOn) 110 | { 111 | if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) { 112 | if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) { 113 | Serial.println("Red btn hit"); 114 | redBtn(); 115 | } 116 | } 117 | } 118 | else //Record is off (RecordOn == false) 119 | { 120 | if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) { 121 | if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) { 122 | Serial.println("Green btn hit"); 123 | greenBtn(); 124 | } 125 | } 126 | } 127 | 128 | Serial.println(RecordOn); 129 | } 130 | } 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /examples/avr/spitftbitmap/spitftbitmap.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our Bitmap drawing example for the Adafruit ILI9341 Breakout and Shield 3 | ----> http://www.adafruit.com/products/1651 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 | 17 | #include // Core graphics library 18 | #include "Adafruit_ILI9341.h" // Hardware-specific library 19 | #include 20 | #include 21 | 22 | // TFT display and SD card will share the hardware SPI interface. 23 | // Hardware SPI pins are specific to the Arduino board type and 24 | // cannot be remapped to alternate pins. For Arduino Uno, 25 | // Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK. 26 | 27 | #define TFT_DC 9 28 | #define TFT_CS 10 29 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 30 | 31 | #define SD_CS 4 32 | 33 | void setup(void) { 34 | Serial.begin(9600); 35 | 36 | tft.begin(); 37 | tft.fillScreen(ILI9341_BLUE); 38 | 39 | Serial.print("Initializing SD card..."); 40 | if (!SD.begin(SD_CS)) { 41 | Serial.println("failed!"); 42 | } 43 | Serial.println("OK!"); 44 | 45 | bmpDraw("purple.bmp", 0, 0); 46 | } 47 | 48 | void loop() { 49 | } 50 | 51 | // This function opens a Windows Bitmap (BMP) file and 52 | // displays it at the given coordinates. It's sped up 53 | // by reading many pixels worth of data at a time 54 | // (rather than pixel by pixel). Increasing the buffer 55 | // size takes more of the Arduino's precious RAM but 56 | // makes loading a little faster. 20 pixels seems a 57 | // good balance. 58 | 59 | #define BUFFPIXEL 20 60 | 61 | void bmpDraw(char *filename, uint8_t x, uint16_t y) { 62 | 63 | File bmpFile; 64 | int bmpWidth, bmpHeight; // W+H in pixels 65 | uint8_t bmpDepth; // Bit depth (currently must be 24) 66 | uint32_t bmpImageoffset; // Start of image data in file 67 | uint32_t rowSize; // Not always = bmpWidth; may have padding 68 | uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel) 69 | uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer 70 | boolean goodBmp = false; // Set to true on valid header parse 71 | boolean flip = true; // BMP is stored bottom-to-top 72 | int w, h, row, col; 73 | uint8_t r, g, b; 74 | uint32_t pos = 0, startTime = millis(); 75 | 76 | if((x >= tft.width()) || (y >= tft.height())) return; 77 | 78 | Serial.println(); 79 | Serial.print(F("Loading image '")); 80 | Serial.print(filename); 81 | Serial.println('\''); 82 | 83 | // Open requested file on SD card 84 | if ((bmpFile = SD.open(filename)) == NULL) { 85 | Serial.print(F("File not found")); 86 | return; 87 | } 88 | 89 | // Parse BMP header 90 | if(read16(bmpFile) == 0x4D42) { // BMP signature 91 | Serial.print(F("File size: ")); Serial.println(read32(bmpFile)); 92 | (void)read32(bmpFile); // Read & ignore creator bytes 93 | bmpImageoffset = read32(bmpFile); // Start of image data 94 | Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC); 95 | // Read DIB header 96 | Serial.print(F("Header size: ")); Serial.println(read32(bmpFile)); 97 | bmpWidth = read32(bmpFile); 98 | bmpHeight = read32(bmpFile); 99 | if(read16(bmpFile) == 1) { // # planes -- must be '1' 100 | bmpDepth = read16(bmpFile); // bits per pixel 101 | Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth); 102 | if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed 103 | 104 | goodBmp = true; // Supported BMP format -- proceed! 105 | Serial.print(F("Image size: ")); 106 | Serial.print(bmpWidth); 107 | Serial.print('x'); 108 | Serial.println(bmpHeight); 109 | 110 | // BMP rows are padded (if needed) to 4-byte boundary 111 | rowSize = (bmpWidth * 3 + 3) & ~3; 112 | 113 | // If bmpHeight is negative, image is in top-down order. 114 | // This is not canon but has been observed in the wild. 115 | if(bmpHeight < 0) { 116 | bmpHeight = -bmpHeight; 117 | flip = false; 118 | } 119 | 120 | // Crop area to be loaded 121 | w = bmpWidth; 122 | h = bmpHeight; 123 | if((x+w-1) >= tft.width()) w = tft.width() - x; 124 | if((y+h-1) >= tft.height()) h = tft.height() - y; 125 | 126 | // Set TFT address window to clipped image bounds 127 | tft.setAddrWindow(x, y, x+w-1, y+h-1); 128 | 129 | for (row=0; row= sizeof(sdbuffer)) { // Indeed 149 | bmpFile.read(sdbuffer, sizeof(sdbuffer)); 150 | buffidx = 0; // Set index to beginning 151 | } 152 | 153 | // Convert pixel from BMP to TFT format, push to display 154 | b = sdbuffer[buffidx++]; 155 | g = sdbuffer[buffidx++]; 156 | r = sdbuffer[buffidx++]; 157 | tft.pushColor(tft.color565(r,g,b)); 158 | } // end pixel 159 | } // end scanline 160 | Serial.print(F("Loaded in ")); 161 | Serial.print(millis() - startTime); 162 | Serial.println(" ms"); 163 | } // end goodBmp 164 | } 165 | } 166 | 167 | bmpFile.close(); 168 | if(!goodBmp) Serial.println(F("BMP format not recognized.")); 169 | } 170 | 171 | // These read 16- and 32-bit types from the SD card file. 172 | // BMP data is stored little-endian, Arduino is little-endian too. 173 | // May need to reverse subscript order if porting elsewhere. 174 | 175 | uint16_t read16(File &f) { 176 | uint16_t result; 177 | ((uint8_t *)&result)[0] = f.read(); // LSB 178 | ((uint8_t *)&result)[1] = f.read(); // MSB 179 | return result; 180 | } 181 | 182 | uint32_t read32(File &f) { 183 | uint32_t result; 184 | ((uint8_t *)&result)[0] = f.read(); // LSB 185 | ((uint8_t *)&result)[1] = f.read(); 186 | ((uint8_t *)&result)[2] = f.read(); 187 | ((uint8_t *)&result)[3] = f.read(); // MSB 188 | return result; 189 | } 190 | -------------------------------------------------------------------------------- /examples/avr/touchpaint/touchpaint.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is our touchscreen painting example for the Adafruit ILI9341 Shield 3 | ----> http://www.adafruit.com/products/1651 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 | 17 | #include // Core graphics library 18 | #include 19 | #include // this is needed even tho we aren't using it 20 | #include 21 | #include 22 | 23 | // This is calibration data for the raw touch data to the screen coordinates 24 | #define TS_MINX 150 25 | #define TS_MINY 130 26 | #define TS_MAXX 3800 27 | #define TS_MAXY 4000 28 | 29 | // The STMPE610 uses hardware SPI on the shield, and #8 30 | #define STMPE_CS 8 31 | Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS); 32 | 33 | // The display also uses hardware SPI, plus #9 & #10 34 | #define TFT_CS 10 35 | #define TFT_DC 9 36 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 37 | 38 | // Size of the color selection boxes and the paintbrush size 39 | #define BOXSIZE 40 40 | #define PENRADIUS 3 41 | int oldcolor, currentcolor; 42 | 43 | void setup(void) { 44 | // while (!Serial); // used for leonardo debugging 45 | 46 | Serial.begin(9600); 47 | Serial.println(F("Touch Paint!")); 48 | 49 | tft.begin(); 50 | 51 | if (!ts.begin()) { 52 | Serial.println("Couldn't start touchscreen controller"); 53 | while (1); 54 | } 55 | Serial.println("Touchscreen started"); 56 | 57 | tft.fillScreen(ILI9341_BLACK); 58 | 59 | // make the color selection boxes 60 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); 61 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); 62 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); 63 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); 64 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); 65 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); 66 | 67 | // select the current color 'red' 68 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 69 | currentcolor = ILI9341_RED; 70 | } 71 | 72 | 73 | void loop() 74 | { 75 | // See if there's any touch data for us 76 | if (ts.bufferEmpty()) { 77 | return; 78 | } 79 | /* 80 | // You can also wait for a touch 81 | if (! ts.touched()) { 82 | return; 83 | } 84 | */ 85 | 86 | // Retrieve a point 87 | TS_Point p = ts.getPoint(); 88 | 89 | /* 90 | Serial.print("X = "); Serial.print(p.x); 91 | Serial.print("\tY = "); Serial.print(p.y); 92 | Serial.print("\tPressure = "); Serial.println(p.z); 93 | */ 94 | 95 | // Scale from ~0->4000 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 | Serial.print("("); Serial.print(p.x); 101 | Serial.print(", "); Serial.print(p.y); 102 | Serial.println(")"); 103 | */ 104 | 105 | if (p.y < BOXSIZE) { 106 | oldcolor = currentcolor; 107 | 108 | if (p.x < BOXSIZE) { 109 | currentcolor = ILI9341_RED; 110 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 111 | } else if (p.x < BOXSIZE*2) { 112 | currentcolor = ILI9341_YELLOW; 113 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 114 | } else if (p.x < BOXSIZE*3) { 115 | currentcolor = ILI9341_GREEN; 116 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 117 | } else if (p.x < BOXSIZE*4) { 118 | currentcolor = ILI9341_CYAN; 119 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 120 | } else if (p.x < BOXSIZE*5) { 121 | currentcolor = ILI9341_BLUE; 122 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 123 | } else if (p.x < BOXSIZE*6) { 124 | currentcolor = ILI9341_MAGENTA; 125 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 126 | } 127 | 128 | if (oldcolor != currentcolor) { 129 | if (oldcolor == ILI9341_RED) 130 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); 131 | if (oldcolor == ILI9341_YELLOW) 132 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); 133 | if (oldcolor == ILI9341_GREEN) 134 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); 135 | if (oldcolor == ILI9341_CYAN) 136 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); 137 | if (oldcolor == ILI9341_BLUE) 138 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); 139 | if (oldcolor == ILI9341_MAGENTA) 140 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); 141 | } 142 | } 143 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 144 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /examples/esp/graphicstest_esp/graphicstest.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // For the Adafruit shield, these are the default. 5 | #define TFT_DC 4 6 | #define TFT_CS 5 7 | 8 | // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC 9 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 10 | 11 | #define SERIAL_OUT Serial 12 | 13 | unsigned long testFillScreen() { 14 | unsigned long start = micros(); 15 | tft.fillScreen(ILI9341_BLACK); 16 | tft.fillScreen(ILI9341_RED); 17 | tft.fillScreen(ILI9341_GREEN); 18 | tft.fillScreen(ILI9341_BLUE); 19 | tft.fillScreen(ILI9341_BLACK); 20 | return micros() - start; 21 | } 22 | 23 | unsigned long testText() { 24 | tft.fillScreen(ILI9341_BLACK); 25 | unsigned long start = micros(); 26 | tft.setCursor(0, 0); 27 | tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); 28 | tft.println("Hello World!"); 29 | tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); 30 | tft.println(1234.56); 31 | tft.setTextColor(ILI9341_RED); tft.setTextSize(3); 32 | tft.println(0xDEADBEEF, HEX); 33 | tft.println(); 34 | tft.setTextColor(ILI9341_GREEN); 35 | tft.setTextSize(5); 36 | tft.println("Groop"); 37 | tft.setTextSize(2); 38 | tft.println("I implore thee,"); 39 | tft.setTextSize(1); 40 | tft.println("my foonting turlingdromes."); 41 | tft.println("And hooptiously drangle me"); 42 | tft.println("with crinkly bindlewurdles,"); 43 | tft.println("Or I will rend thee"); 44 | tft.println("in the gobberwarts"); 45 | tft.println("with my blurglecruncheon,"); 46 | tft.println("see if I don't!"); 47 | return micros() - start; 48 | } 49 | 50 | unsigned long testLines(uint16_t color) { 51 | unsigned long start, t; 52 | int x1, y1, x2, y2, 53 | w = tft.width(), 54 | h = tft.height(); 55 | 56 | tft.fillScreen(ILI9341_BLACK); 57 | delay(0); 58 | 59 | x1 = y1 = 0; 60 | y2 = h - 1; 61 | start = micros(); 62 | for(x2=0; x20; i-=6) { 143 | delay(0); 144 | i2 = i / 2; 145 | start = micros(); 146 | tft.fillRect(cx-i2, cy-i2, i, i, color1); 147 | t += micros() - start; 148 | // Outlines are not included in timing results 149 | tft.drawRect(cx-i2, cy-i2, i, i, color2); 150 | } 151 | 152 | return t; 153 | } 154 | 155 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 156 | unsigned long start; 157 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 158 | 159 | tft.fillScreen(ILI9341_BLACK); 160 | start = micros(); 161 | for(x=radius; x10; i-=5) { 215 | start = micros(); 216 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 217 | tft.color565(0, i, i)); 218 | t += micros() - start; 219 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 220 | tft.color565(i, i, 0)); 221 | } 222 | 223 | return t; 224 | } 225 | 226 | unsigned long testRoundRects() { 227 | unsigned long start; 228 | int w, i, i2, 229 | cx = tft.width() / 2 - 1, 230 | cy = tft.height() / 2 - 1; 231 | 232 | tft.fillScreen(ILI9341_BLACK); 233 | w = min(tft.width(), tft.height()); 234 | start = micros(); 235 | for(i=0; i20; i-=6) { 253 | i2 = i / 2; 254 | tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); 255 | delay(0); 256 | } 257 | 258 | return micros() - start; 259 | } 260 | 261 | 262 | void setup() { 263 | SERIAL_OUT.begin(921600); 264 | SERIAL_OUT.println("ILI9341 Test!"); 265 | 266 | tft.begin(); 267 | 268 | // read diagnostics (optional but can help debug problems) 269 | uint8_t x = tft.readcommand8(ILI9341_RDMODE); 270 | SERIAL_OUT.print("Display Power Mode: 0x"); SERIAL_OUT.println(x, HEX); 271 | x = tft.readcommand8(ILI9341_RDMADCTL); 272 | SERIAL_OUT.print("MADCTL Mode: 0x"); SERIAL_OUT.println(x, HEX); 273 | x = tft.readcommand8(ILI9341_RDPIXFMT); 274 | SERIAL_OUT.print("Pixel Format: 0x"); SERIAL_OUT.println(x, HEX); 275 | x = tft.readcommand8(ILI9341_RDIMGFMT); 276 | SERIAL_OUT.print("Image Format: 0x"); SERIAL_OUT.println(x, HEX); 277 | x = tft.readcommand8(ILI9341_RDSELFDIAG); 278 | SERIAL_OUT.print("Self Diagnostic: 0x"); SERIAL_OUT.println(x, HEX); 279 | 280 | SERIAL_OUT.println(F("Benchmark Time (microseconds)")); 281 | 282 | SERIAL_OUT.print(F("Screen fill ")); 283 | SERIAL_OUT.println(testFillScreen()); 284 | delay(500); 285 | 286 | SERIAL_OUT.print(F("Text ")); 287 | SERIAL_OUT.println(testText()); 288 | delay(3000); 289 | 290 | SERIAL_OUT.print(F("Lines ")); 291 | SERIAL_OUT.println(testLines(ILI9341_CYAN)); 292 | delay(500); 293 | 294 | SERIAL_OUT.print(F("Horiz/Vert Lines ")); 295 | SERIAL_OUT.println(testFastLines(ILI9341_RED, ILI9341_BLUE)); 296 | delay(500); 297 | 298 | SERIAL_OUT.print(F("Rectangles (outline) ")); 299 | SERIAL_OUT.println(testRects(ILI9341_GREEN)); 300 | delay(500); 301 | 302 | SERIAL_OUT.print(F("Rectangles (filled) ")); 303 | SERIAL_OUT.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA)); 304 | delay(500); 305 | 306 | SERIAL_OUT.print(F("Circles (filled) ")); 307 | SERIAL_OUT.println(testFilledCircles(10, ILI9341_MAGENTA)); 308 | 309 | SERIAL_OUT.print(F("Circles (outline) ")); 310 | SERIAL_OUT.println(testCircles(10, ILI9341_WHITE)); 311 | delay(500); 312 | 313 | SERIAL_OUT.print(F("Triangles (outline) ")); 314 | SERIAL_OUT.println(testTriangles()); 315 | delay(500); 316 | 317 | SERIAL_OUT.print(F("Triangles (filled) ")); 318 | SERIAL_OUT.println(testFilledTriangles()); 319 | delay(500); 320 | 321 | SERIAL_OUT.print(F("Rounded rects (outline) ")); 322 | SERIAL_OUT.println(testRoundRects()); 323 | delay(500); 324 | 325 | SERIAL_OUT.print(F("Rounded rects (filled) ")); 326 | SERIAL_OUT.println(testFilledRoundRects()); 327 | delay(500); 328 | 329 | SERIAL_OUT.println(F("Done!")); 330 | 331 | } 332 | 333 | 334 | void loop(void) { 335 | for(uint8_t rotation=0; rotation<4; rotation++) { 336 | tft.setRotation(rotation); 337 | testText(); 338 | delay(1000); 339 | } 340 | } 341 | 342 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit ILI9341 2 | version=1.0.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Library for Adafruit ILI9341 displays 6 | paragraph=Library for Adafruit ILI9341 displays 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit_ILI9341 9 | architectures=* 10 | -------------------------------------------------------------------------------- /travis/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function build_sketches() 4 | { 5 | local arduino=$1 6 | local srcpath=$2 7 | local platform=$3 8 | local sketches=$(find $srcpath -name *.ino) 9 | for sketch in $sketches; do 10 | local sketchdir=$(dirname $sketch) 11 | if [[ -f "$sketchdir/.$platform.skip" ]]; then 12 | echo -e "\n\n ------------ Skipping $sketch ------------ \n\n"; 13 | continue 14 | fi 15 | echo -e "\n\n ------------ Building $sketch ------------ \n\n"; 16 | $arduino --verify $sketch; 17 | local result=$? 18 | if [ $result -ne 0 ]; then 19 | echo "Build failed ($sketch) build verbose..." 20 | $arduino --verify --verbose --preserve-temp-files $sketch 21 | result=$? 22 | fi 23 | if [ $result -ne 0 ]; then 24 | echo "Build failed ($1) $sketch" 25 | return $result 26 | fi 27 | done 28 | } 29 | 30 | function build_sketch() 31 | { 32 | local arduino=$1 33 | local sketch=$2 34 | $arduino --verify $sketch; 35 | local result=$? 36 | if [ $result -ne 0 ]; then 37 | echo "Build failed ($sketch) build verbose..." 38 | $arduino --verify --verbose --preserve-temp-files $sketch 39 | result=$? 40 | fi 41 | if [ $result -ne 0 ]; then 42 | echo "Build failed ($1) $sketch" 43 | return $result 44 | fi 45 | } 46 | 47 | function get_sketches_json() 48 | { 49 | local arduino=$1 50 | local srcpath=$2 51 | local platform=$3 52 | local sketches=($(find $srcpath -name *.ino)) 53 | echo -en "[" 54 | for sketch in "${sketches[@]}" ; do 55 | local sketchdir=$(dirname $sketch) 56 | if [[ -f "$sketchdir/.$platform.skip" ]]; then 57 | continue 58 | fi 59 | echo -en "\"$sketch\"" 60 | if [[ $sketch != ${sketches[-1]} ]] ; then 61 | echo -en "," 62 | fi 63 | 64 | done 65 | echo -en "]" 66 | } 67 | 68 | function get_sketches_json_matrix() 69 | { 70 | local arduino=$1 71 | local srcpath=$2 72 | local platform=$3 73 | local ideversion=$4 74 | local board=$5 75 | local sketches=($(find $srcpath -name *.ino)) 76 | for sketch in "${sketches[@]}" ; do 77 | local sketchdir=$(dirname $sketch) 78 | local sketchname=$(basename $sketch) 79 | if [[ -f "$sketchdir/.$platform.skip" ]]; then 80 | continue 81 | fi 82 | echo -en "{\"name\":\"$sketchname\",\"board\":\"$board\",\"ideversion\":\"$ideversion\",\"cpu\":\"$platform\",\"sketch\":\"$sketch\"}" 83 | if [[ $sketch != ${sketches[-1]} ]] ; then 84 | echo -en "," 85 | fi 86 | done 87 | } 88 | 89 | function get_core() 90 | { 91 | echo Setup core for $1 92 | 93 | cd $HOME/arduino_ide/hardware 94 | 95 | if [ "$1" = "esp8266" ] ; then 96 | mkdir esp8266com 97 | cd esp8266com 98 | git clone --depth 1 https://github.com/esp8266/Arduino.git esp8266 99 | cd esp8266/ 100 | rm -rf .git 101 | cd tools 102 | python get.py 103 | fi 104 | 105 | if [ "$1" = "esp32" ] ; then 106 | mkdir espressif 107 | cd espressif 108 | git clone --depth 1 https://github.com/espressif/arduino-esp32.git esp32 109 | cd esp32/ 110 | rm -rf .git 111 | cd tools 112 | python get.py 113 | fi 114 | 115 | } 116 | 117 | function clone_library() { 118 | local url=$1 119 | echo clone $(basename $url) 120 | mkdir -p $HOME/Arduino/libraries 121 | cd $HOME/Arduino/libraries 122 | git clone --depth 1 $url 123 | rm -rf */.git 124 | rm -rf */.github 125 | rm -rf */examples 126 | } 127 | 128 | function hash_library_names() { 129 | cd $HOME/Arduino/libraries 130 | ls | sha1sum -z | cut -c1-5 131 | } --------------------------------------------------------------------------------