mock_ili9341.ino (9790B)
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 delay(10); 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 yield(); 114 tft.fillScreen(ILI9341_RED); 115 yield(); 116 tft.fillScreen(ILI9341_GREEN); 117 yield(); 118 tft.fillScreen(ILI9341_BLUE); 119 yield(); 120 tft.fillScreen(ILI9341_BLACK); 121 yield(); 122 return micros() - start; 123 } 124 125 unsigned long testText() { 126 tft.fillScreen(ILI9341_BLACK); 127 unsigned long start = micros(); 128 tft.setCursor(0, 0); 129 tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); 130 tft.println("Hello World!"); 131 tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); 132 tft.println(1234.56); 133 tft.setTextColor(ILI9341_RED); tft.setTextSize(3); 134 tft.println(0xDEADBEEF, HEX); 135 tft.println(); 136 tft.setTextColor(ILI9341_GREEN); 137 tft.setTextSize(5); 138 tft.println("Groop"); 139 tft.setTextSize(2); 140 tft.println("I implore thee,"); 141 tft.setTextSize(1); 142 tft.println("my foonting turlingdromes."); 143 tft.println("And hooptiously drangle me"); 144 tft.println("with crinkly bindlewurdles,"); 145 tft.println("Or I will rend thee"); 146 tft.println("in the gobberwarts"); 147 tft.println("with my blurglecruncheon,"); 148 tft.println("see if I don't!"); 149 return micros() - start; 150 } 151 152 unsigned long testLines(uint16_t color) { 153 unsigned long start, t; 154 int x1, y1, x2, y2, 155 w = tft.width(), 156 h = tft.height(); 157 158 tft.fillScreen(ILI9341_BLACK); 159 yield(); 160 161 x1 = y1 = 0; 162 y2 = h - 1; 163 start = micros(); 164 for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); 165 x2 = w - 1; 166 for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); 167 t = micros() - start; // fillScreen doesn't count against timing 168 169 yield(); 170 tft.fillScreen(ILI9341_BLACK); 171 yield(); 172 173 x1 = w - 1; 174 y1 = 0; 175 y2 = h - 1; 176 start = micros(); 177 for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); 178 x2 = 0; 179 for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); 180 t += micros() - start; 181 182 yield(); 183 tft.fillScreen(ILI9341_BLACK); 184 yield(); 185 186 x1 = 0; 187 y1 = h - 1; 188 y2 = 0; 189 start = micros(); 190 for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); 191 x2 = w - 1; 192 for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); 193 t += micros() - start; 194 195 yield(); 196 tft.fillScreen(ILI9341_BLACK); 197 yield(); 198 199 x1 = w - 1; 200 y1 = h - 1; 201 y2 = 0; 202 start = micros(); 203 for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); 204 x2 = 0; 205 for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); 206 207 yield(); 208 return micros() - start; 209 } 210 211 unsigned long testFastLines(uint16_t color1, uint16_t color2) { 212 unsigned long start; 213 int x, y, w = tft.width(), h = tft.height(); 214 215 tft.fillScreen(ILI9341_BLACK); 216 start = micros(); 217 for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1); 218 for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2); 219 220 return micros() - start; 221 } 222 223 unsigned long testRects(uint16_t color) { 224 unsigned long start; 225 int n, i, i2, 226 cx = tft.width() / 2, 227 cy = tft.height() / 2; 228 229 tft.fillScreen(ILI9341_BLACK); 230 n = min(tft.width(), tft.height()); 231 start = micros(); 232 for(i=2; i<n; i+=6) { 233 i2 = i / 2; 234 tft.drawRect(cx-i2, cy-i2, i, i, color); 235 } 236 237 return micros() - start; 238 } 239 240 unsigned long testFilledRects(uint16_t color1, uint16_t color2) { 241 unsigned long start, t = 0; 242 int n, i, i2, 243 cx = tft.width() / 2 - 1, 244 cy = tft.height() / 2 - 1; 245 246 tft.fillScreen(ILI9341_BLACK); 247 n = min(tft.width(), tft.height()); 248 for(i=n; i>0; i-=6) { 249 i2 = i / 2; 250 start = micros(); 251 tft.fillRect(cx-i2, cy-i2, i, i, color1); 252 t += micros() - start; 253 // Outlines are not included in timing results 254 tft.drawRect(cx-i2, cy-i2, i, i, color2); 255 yield(); 256 } 257 258 return t; 259 } 260 261 unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 262 unsigned long start; 263 int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 264 265 tft.fillScreen(ILI9341_BLACK); 266 start = micros(); 267 for(x=radius; x<w; x+=r2) { 268 for(y=radius; y<h; y+=r2) { 269 tft.fillCircle(x, y, radius, color); 270 } 271 } 272 273 return micros() - start; 274 } 275 276 unsigned long testCircles(uint8_t radius, uint16_t color) { 277 unsigned long start; 278 int x, y, r2 = radius * 2, 279 w = tft.width() + radius, 280 h = tft.height() + radius; 281 282 // Screen is not cleared for this one -- this is 283 // intentional and does not affect the reported time. 284 start = micros(); 285 for(x=0; x<w; x+=r2) { 286 for(y=0; y<h; y+=r2) { 287 tft.drawCircle(x, y, radius, color); 288 } 289 } 290 291 return micros() - start; 292 } 293 294 unsigned long testTriangles() { 295 unsigned long start; 296 int n, i, cx = tft.width() / 2 - 1, 297 cy = tft.height() / 2 - 1; 298 299 tft.fillScreen(ILI9341_BLACK); 300 n = min(cx, cy); 301 start = micros(); 302 for(i=0; i<n; i+=5) { 303 tft.drawTriangle( 304 cx , cy - i, // peak 305 cx - i, cy + i, // bottom left 306 cx + i, cy + i, // bottom right 307 tft.color565(i, i, i)); 308 } 309 310 return micros() - start; 311 } 312 313 unsigned long testFilledTriangles() { 314 unsigned long start, t = 0; 315 int i, cx = tft.width() / 2 - 1, 316 cy = tft.height() / 2 - 1; 317 318 tft.fillScreen(ILI9341_BLACK); 319 start = micros(); 320 for(i=min(cx,cy); i>10; i-=5) { 321 start = micros(); 322 tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 323 tft.color565(0, i*10, i*10)); 324 t += micros() - start; 325 tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 326 tft.color565(i*10, i*10, 0)); 327 yield(); 328 } 329 330 return t; 331 } 332 333 unsigned long testRoundRects() { 334 unsigned long start; 335 int w, i, i2, 336 cx = tft.width() / 2 - 1, 337 cy = tft.height() / 2 - 1; 338 339 tft.fillScreen(ILI9341_BLACK); 340 w = min(tft.width(), tft.height()); 341 start = micros(); 342 for(i=0; i<w; i+=6) { 343 i2 = i / 2; 344 tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0)); 345 } 346 347 return micros() - start; 348 } 349 350 unsigned long testFilledRoundRects() { 351 unsigned long start; 352 int i, i2, 353 cx = tft.width() / 2 - 1, 354 cy = tft.height() / 2 - 1; 355 356 tft.fillScreen(ILI9341_BLACK); 357 start = micros(); 358 for(i=min(tft.width(), tft.height()); i>20; i-=6) { 359 i2 = i / 2; 360 tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); 361 yield(); 362 } 363 364 return micros() - start; 365 }