Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <Adafruit_GFX.h>    // Core graphics library
  2. #include <Adafruit_TFTLCD.h> // Hardware-specific library
  3.  
  4. // The control pins for the LCD can be assigned to any digital or
  5. // analog pins...but we'll use the analog pins as this allows us to
  6. // double up the pins with the touch screen (see the TFT paint example).
  7. #define LCD_CS A3 //
  8. #define LCD_CD A2 //
  9. #define LCD_WR A1 //
  10. #define LCD_RD A0 //
  11. #define LCD_RESET A4 //
  12.  
  13. // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
  14. // For the Arduino Uno, Duemilanove, Diecimila, etc.:
  15. //   D0 connects to digital pin 8  (Notice these are
  16. //   D1 connects to digital pin 9   NOT in order!)
  17. //   D2 connects to digital pin 2
  18. //   D3 connects to digital pin 3
  19. //   D4 connects to digital pin 4
  20. //   D5 connects to digital pin 5
  21. //   D6 connects to digital pin 6
  22. //   D7 connects to digital pin 7
  23. // For the Arduino Mega, use digital pins 22 through 29
  24. // (on the 2-row header at the end of the board).
  25.  
  26. // Assign human-readable names to some common 16-bit color values:
  27. #define   BLACK   0x0000
  28. #define   BLUE    0x001F
  29. #define   RED     0xF800
  30. #define   GREEN   0x07E0
  31. #define CYAN    0x07FF
  32. #define MAGENTA 0xF81F
  33. #define YELLOW  0xFFE0
  34. #define WHITE   0xFFFF
  35.  
  36. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  37. // If using the shield, all control and data lines are fixed, and
  38. // a simpler declaration can optionally be used:
  39. // Adafruit_TFTLCD tft;
  40.  
  41. void setup(void) {
  42.   Serial.begin(9600);
  43.   Serial.println(F("TFT LCD test"));
  44.  
  45. #ifdef USE_ADAFRUIT_SHIELD_PINOUT
  46.   Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
  47. #else
  48.   Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
  49. #endif
  50.  
  51.   Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
  52.  
  53.   tft.reset();
  54.  
  55.   uint16_t identifier = tft.readID();
  56.  
  57.   if(identifier == 0x9325) {
  58.     Serial.println(F("Found ILI9325 LCD driver"));
  59.   } else if(identifier == 0x9328) {
  60.     Serial.println(F("Found ILI9328 LCD driver"));
  61.   } else if(identifier == 0x7575) {
  62.     Serial.println(F("Found HX8347G LCD driver"));
  63.   } else if(identifier == 0x9341) {
  64.     Serial.println(F("Found ILI9341 LCD driver"));
  65.   } else if(identifier == 0x8357) {
  66.     Serial.println(F("Found HX8357D LCD driver"));
  67.   } else {
  68.     Serial.print(F("Unknown LCD driver chip: "));
  69.     Serial.println(identifier, HEX);
  70.     Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
  71.     Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
  72.     Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
  73.     Serial.println(F("If using the breakout board, it should NOT be #defined!"));
  74.     Serial.println(F("Also if using the breakout, double-check that all wiring"));
  75.     Serial.println(F("matches the tutorial."));
  76.     // return;
  77.   }
  78.  
  79.   //tft.begin(identifier);
  80.   tft.begin(0x9341);
  81.  
  82.   Serial.println(F("Benchmark                Time (microseconds)"));
  83.  
  84.   Serial.print(F("Screen fill              "));
  85.   Serial.println(testFillScreen());
  86.   delay(500);
  87.  
  88.   Serial.print(F("Text                     "));
  89.   Serial.println(testText());
  90.   delay(3000);
  91.  
  92.   Serial.print(F("Lines                    "));
  93.   Serial.println(testLines(CYAN));
  94.   delay(500);
  95.  
  96.   Serial.print(F("Horiz/Vert Lines         "));
  97.   Serial.println(testFastLines(RED, BLUE));
  98.   delay(500);
  99.  
  100.   Serial.print(F("Rectangles (outline)     "));
  101.   Serial.println(testRects(GREEN));
  102.   delay(500);
  103.  
  104.   Serial.print(F("Rectangles (filled)      "));
  105.   Serial.println(testFilledRects(YELLOW, MAGENTA));
  106.   delay(500);
  107.  
  108.   Serial.print(F("Circles (filled)         "));
  109.   Serial.println(testFilledCircles(10, MAGENTA));
  110.  
  111.   Serial.print(F("Circles (outline)        "));
  112.   Serial.println(testCircles(10, WHITE));
  113.   delay(500);
  114.  
  115.   Serial.print(F("Triangles (outline)      "));
  116.   Serial.println(testTriangles());
  117.   delay(500);
  118.  
  119.   Serial.print(F("Triangles (filled)       "));
  120.   Serial.println(testFilledTriangles());
  121.   delay(500);
  122.  
  123.   Serial.print(F("Rounded rects (outline)  "));
  124.   Serial.println(testRoundRects());
  125.   delay(500);
  126.  
  127.   Serial.print(F("Rounded rects (filled)   "));
  128.   Serial.println(testFilledRoundRects());
  129.   delay(500);
  130.  
  131.   Serial.println(F("Done!"));
  132. }
  133.  
  134. void loop(void) {
  135.   for(uint8_t rotation=0; rotation<4; rotation++) {
  136.     tft.setRotation(rotation);
  137.     testText();
  138.     delay(2000);
  139.   }
  140. }
  141.  
  142. unsigned long testFillScreen() {
  143.   unsigned long start = micros();
  144.   tft.fillScreen(BLACK);
  145.   tft.fillScreen(RED);
  146.   tft.fillScreen(GREEN);
  147.   tft.fillScreen(BLUE);
  148.   tft.fillScreen(BLACK);
  149.   return micros() - start;
  150. }
  151.  
  152. unsigned long testText() {
  153.   tft.fillScreen(BLACK);
  154.   unsigned long start = micros();
  155.   tft.setCursor(0, 0);
  156.   tft.setTextColor(WHITE);  tft.setTextSize(1);
  157.   tft.println("Hello World!");
  158.   tft.setTextColor(YELLOW); tft.setTextSize(2);
  159.   tft.println(1234.56);
  160.   tft.setTextColor(RED);    tft.setTextSize(3);
  161.   tft.println(0xDEADBEEF, HEX);
  162.   tft.println();
  163.   tft.setTextColor(GREEN);
  164.   tft.setTextSize(5);
  165.   tft.println("Groop");
  166.   tft.setTextSize(2);
  167.   tft.println("I implore thee,");
  168.   tft.setTextSize(1);
  169.   tft.println("my foonting turlingdromes.");
  170.   tft.println("And hooptiously drangle me");
  171.   tft.println("with crinkly bindlewurdles,");
  172.   tft.println("Or I will rend thee");
  173.   tft.println("in the gobberwarts");
  174.   tft.println("with my blurglecruncheon,");
  175.   tft.println("see if I don't!");
  176.   return micros() - start;
  177. }
  178.  
  179. unsigned long testLines(uint16_t color) {
  180.   unsigned long start, t;
  181.   int           x1, y1, x2, y2,
  182.                 w = tft.width(),
  183.                 h = tft.height();
  184.  
  185.   tft.fillScreen(BLACK);
  186.  
  187.   x1 = y1 = 0;
  188.   y2    = h - 1;
  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; // fillScreen doesn't count against timing
  194.  
  195.   tft.fillScreen(BLACK);
  196.  
  197.   x1    = w - 1;
  198.   y1    = 0;
  199.   y2    = h - 1;
  200.   start = micros();
  201.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  202.   x2    = 0;
  203.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  204.   t    += micros() - start;
  205.  
  206.   tft.fillScreen(BLACK);
  207.  
  208.   x1    = 0;
  209.   y1    = h - 1;
  210.   y2    = 0;
  211.   start = micros();
  212.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  213.   x2    = w - 1;
  214.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  215.   t    += micros() - start;
  216.  
  217.   tft.fillScreen(BLACK);
  218.  
  219.   x1    = w - 1;
  220.   y1    = h - 1;
  221.   y2    = 0;
  222.   start = micros();
  223.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  224.   x2    = 0;
  225.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  226.  
  227.   return micros() - start;
  228. }
  229.  
  230. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  231.   unsigned long start;
  232.   int           x, y, w = tft.width(), h = tft.height();
  233.  
  234.   tft.fillScreen(BLACK);
  235.   start = micros();
  236.   for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  237.   for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
  238.  
  239.   return micros() - start;
  240. }
  241.  
  242. unsigned long testRects(uint16_t color) {
  243.   unsigned long start;
  244.   int           n, i, i2,
  245.                 cx = tft.width()  / 2,
  246.                 cy = tft.height() / 2;
  247.  
  248.   tft.fillScreen(BLACK);
  249.   n     = min(tft.width(), tft.height());
  250.   start = micros();
  251.   for(i=2; i<n; i+=6) {
  252.     i2 = i / 2;
  253.     tft.drawRect(cx-i2, cy-i2, i, i, color);
  254.   }
  255.  
  256.   return micros() - start;
  257. }
  258.  
  259. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  260.   unsigned long start, t = 0;
  261.   int           n, i, i2,
  262.                 cx = tft.width()  / 2 - 1,
  263.                 cy = tft.height() / 2 - 1;
  264.  
  265.   tft.fillScreen(BLACK);
  266.   n = min(tft.width(), tft.height());
  267.   for(i=n; i>0; i-=6) {
  268.     i2    = i / 2;
  269.     start = micros();
  270.     tft.fillRect(cx-i2, cy-i2, i, i, color1);
  271.     t    += micros() - start;
  272.     // Outlines are not included in timing results
  273.     tft.drawRect(cx-i2, cy-i2, i, i, color2);
  274.   }
  275.  
  276.   return t;
  277. }
  278.  
  279. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  280.   unsigned long start;
  281.   int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  282.  
  283.   tft.fillScreen(BLACK);
  284.   start = micros();
  285.   for(x=radius; x<w; x+=r2) {
  286.     for(y=radius; y<h; y+=r2) {
  287.       tft.fillCircle(x, y, radius, color);
  288.     }
  289.   }
  290.  
  291.   return micros() - start;
  292. }
  293.  
  294. unsigned long testCircles(uint8_t radius, uint16_t color) {
  295.   unsigned long start;
  296.   int           x, y, r2 = radius * 2,
  297.                 w = tft.width()  + radius,
  298.                 h = tft.height() + radius;
  299.  
  300.   // Screen is not cleared for this one -- this is
  301.   // intentional and does not affect the reported time.
  302.   start = micros();
  303.   for(x=0; x<w; x+=r2) {
  304.     for(y=0; y<h; y+=r2) {
  305.       tft.drawCircle(x, y, radius, color);
  306.     }
  307.   }
  308.  
  309.   return micros() - start;
  310. }
  311.  
  312. unsigned long testTriangles() {
  313.   unsigned long start;
  314.   int           n, i, cx = tft.width()  / 2 - 1,
  315.                       cy = tft.height() / 2 - 1;
  316.  
  317.   tft.fillScreen(BLACK);
  318.   n     = min(cx, cy);
  319.   start = micros();
  320.   for(i=0; i<n; i+=5) {
  321.     tft.drawTriangle(
  322.       cx    , cy - i, // peak
  323.       cx - i, cy + i, // bottom left
  324.       cx + i, cy + i, // bottom right
  325.       tft.color565(0, 0, i));
  326.   }
  327.  
  328.   return micros() - start;
  329. }
  330.  
  331. unsigned long testFilledTriangles() {
  332.   unsigned long start, t = 0;
  333.   int           i, cx = tft.width()  / 2 - 1,
  334.                    cy = tft.height() / 2 - 1;
  335.  
  336.   tft.fillScreen(BLACK);
  337.   start = micros();
  338.   for(i=min(cx,cy); i>10; i-=5) {
  339.     start = micros();
  340.     tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  341.       tft.color565(0, i, i));
  342.     t += micros() - start;
  343.     tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  344.       tft.color565(i, i, 0));
  345.   }
  346.  
  347.   return t;
  348. }
  349.  
  350. unsigned long testRoundRects() {
  351.   unsigned long start;
  352.   int           w, i, i2,
  353.                 cx = tft.width()  / 2 - 1,
  354.                 cy = tft.height() / 2 - 1;
  355.  
  356.   tft.fillScreen(BLACK);
  357.   w     = min(tft.width(), tft.height());
  358.   start = micros();
  359.   for(i=0; i<w; i+=6) {
  360.     i2 = i / 2;
  361.     tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  362.   }
  363.  
  364.   return micros() - start;
  365. }
  366.  
  367. unsigned long testFilledRoundRects() {
  368.   unsigned long start;
  369.   int           i, i2,
  370.                 cx = tft.width()  / 2 - 1,
  371.                 cy = tft.height() / 2 - 1;
  372.  
  373.   tft.fillScreen(BLACK);
  374.   start = micros();
  375.   for(i=min(tft.width(), tft.height()); i>20; i-=6) {
  376.     i2 = i / 2;
  377.     tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  378.   }
  379.  
  380.   return micros() - start;
  381. }