// This version of the test Sketch and additional comments by A.Tedds. // IMPORTANT: Adafruit_ILI9341_8bit_AS LIBRARY MUST BE SPECIFICALLY // CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. // DEFAULT IS THE UNO SHIELD // SEE RELEVANT COMMENTS IN Adafruit_ILI9341_8bit_AS.h FOR SETUP. #define DEBUG #include // Core graphics library #include // Hardware-specific library /* The control pins for the LCD can be assigned to any digital or analog pins...but we'll use the analog pins as this allows us to double up the pins with the touch screen (see the TFT paint example).*/ #define LCD_CS A3 // Chip Select goes to Analog 3 (A3) #define LCD_CD A2 // Command/Data (Labled LCD_RS!!) goes to Analog 2 (A2) #define LCD_WR A1 // LCD Write goes to Analog 1 (A1) #define LCD_RD A0 // LCD Read goes to Analog 0 (A0) #define LCD_RESET A4 // Connected to Analogue 4 (A4) Can alternately just connect to Arduino's reset pin // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: // For the Arduino Uno, Duemilanove, Diecimila, etc.: // D0 connects to digital pin 8 (Notice these are // D1 connects to digital pin 9 NOT in order!) // D2 connects to digital pin 2 // D3 connects to digital pin 3 // D4 connects to digital pin 4 // D5 connects to digital pin 5 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 // (on the 2-row header at the end of the board). // Assign human-readable names to some common 16-bit color values. // These values were inverted in the original sketch. #define WHITE 0x0000 // 0000 0000 0000 0000 (Binary value conversion) #define YELLOW 0x001F // 0000 0000 0001 1111 " #define MAGENTA 0x07E0 // 0000 0111 1110 0000 " #define RED 0x07FF // 0000 0111 1111 1111 " #define CYAN 0xF800 // 1111 1000 0000 0000 " #define GREEN 0xF81F // 1111 1000 0001 1111 " #define BLUE 0xFFE0 // 1111 1111 1110 0000 " #define BLACK 0xFFFF // 1111 1111 1111 1111 " Adafruit_ILI9341_8bit_AS tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // If using the shield, all control and data lines are fixed, and // a simpler declaration can optionally be used: // Adafruit_ILI9341_8bit_AS tft; void setup(void) { #ifdef DEBUG Serial.begin(9600); Serial.println("TFT LCD test"); Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height()); #endif // DEBUG tft.reset(); delay(10); tft.begin(0x9341); #ifdef DEBUG Serial.println("Benchmark Time (microseconds)"); Serial.print("Screen fill "); Serial.println(testFillScreen()); delay(500); Serial.print("Text "); Serial.println(testText()); delay(3000); Serial.print("Lines CYAN "); Serial.println(testLines(CYAN)); delay(500); Serial.print("Horiz/Vert Lines RED,BLUE "); Serial.println(testFastLines(RED, BLUE)); delay(500); Serial.print("Rectangles (outline)GREEN "); Serial.println(testRects(GREEN)); delay(500); Serial.print("Rectangles (filled)YELLOW, MAGENTA "); Serial.println(testFilledRects(YELLOW, MAGENTA)); delay(500); Serial.print("Circles (filled) MAGENTA "); Serial.println(testFilledCircles(10, MAGENTA)); delay (500); Serial.print("Circles (outline) WHITE "); Serial.println(testCircles(10, WHITE)); delay(500); Serial.print("Triangles (outline) "); Serial.println(testTriangles()); delay(500); Serial.print("Triangles (filled) "); Serial.println(testFilledTriangles()); delay(500); Serial.print("Rounded rects (outline) "); Serial.println(testRoundRects()); delay(500); Serial.print("Rounded rects (filled) "); Serial.println(testFilledRoundRects()); delay(500); Serial.println("Done!"); #endif // DEBUG } void loop(void) { for(uint8_t rotation=0; rotation<4; rotation++) { tft.setRotation(rotation); testText(); delay(3000); } testFilledRoundRects(); testRoundRects(); testFilledTriangles(); testTriangles(); testCircles(10, WHITE); testFillScreen(); testText(); testLines(CYAN); testFastLines(RED, BLUE); testRects(GREEN); testFilledRects(YELLOW, MAGENTA); testFilledCircles(10, MAGENTA); } unsigned long testFillScreen() { unsigned long start = micros(); tft.fillScreen(BLACK); tft.fillScreen(RED); tft.fillScreen(GREEN); tft.fillScreen(BLUE); tft.fillScreen(MAGENTA); tft.fillScreen(YELLOW); tft.fillScreen(CYAN); tft.fillScreen(WHITE); return micros() - start; } unsigned long testText() { tft.fillScreen(BLACK); unsigned long start = micros(); tft.setCursor(0, 100); // Sreen Position for start of text. tft.setTextColor(WHITE); tft.setTextSize(3); //Set Text Color White and Font Size 3. tft.println("Hello World!"); tft.setTextColor(YELLOW); tft.setTextSize(2); //Set Text Color Yellow and Font Size 2. tft.println("1234567890."); tft.setTextColor(RED); tft.setTextSize(3); //Set Text Color Red and Font Size 3. tft.println(0x1234ABCD, HEX); //tft.println(); tft.setTextColor(GREEN); tft.setTextSize(3); //Set Text Color Green and Font Size 3. tft.println("Hello World!"); tft.setTextSize(2); tft.println("Hello World!"); tft.setTextSize(1); tft.println("Hello World!"); return micros() - start; } unsigned long testLines(uint16_t color) { unsigned long start, t; int x1, y1, x2, y2, w = tft.width(), h = tft.height(); tft.fillScreen(BLACK); x1 = y1 = 0; y2 = h - 1; start = micros(); for(x2=0; x20; i-=6) { i2 = i / 2; start = micros(); tft.fillRect(cx-i2, cy-i2, i, i, color1); t += micros() - start; // Outlines are not included in timing results tft.drawRect(cx-i2, cy-i2, i, i, color2); } return t; } unsigned long testFilledCircles(uint8_t radius, uint16_t color) { unsigned long start; int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; tft.fillScreen(BLACK); start = micros(); for(x=radius; x10; i-=5) { start = micros(); tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, tft.color565(0, i, i)); t += micros() - start; tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, tft.color565(i, i, 0)); } return t; } unsigned long testRoundRects() { unsigned long start; int w, i, i2, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1; tft.fillScreen(BLACK); w = min(tft.width(), tft.height()); start = micros(); for(i=0; i20; i-=6) { i2 = i / 2; tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); } return micros() - start; }