// Paint example specifically for the TFTLCD breakout board. // If using the Arduino shield, use the tftpaint_shield.pde sketch instead! // DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO //Technical support:goodtft@163.com #include // Core graphics library #include // Hardware-specific library #include #if defined(__SAM3X8E__) #undef __FlashStringHelper::F(string_literal) #define F(string_literal) string_literal #endif // 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). // D0 connects to digital pin 22 // D1 connects to digital pin 23 // D2 connects to digital pin 24 // D3 connects to digital pin 25 // D4 connects to digital pin 26 // D5 connects to digital pin 27 // D6 connects to digital pin 28 // D7 connects to digital pin 29 // For the Arduino Due, use digital pins 33 through 40 // (on the 2-row header at the end of the board). // D0 connects to digital pin 33 // D1 connects to digital pin 34 // D2 connects to digital pin 35 // D3 connects to digital pin 36 // D4 connects to digital pin 37 // D5 connects to digital pin 38 // D6 connects to digital pin 39 // D7 connects to digital pin 40 #define YP A1 // must be an 1023 to tft.width p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0); /* Serial.print("("); Serial.print(p.x); Serial.print(", "); Serial.print(p.y); Serial.println(")"); */ if (p.y < BOXSIZE) { oldcolor = currentcolor; if (p.x < BOXSIZE) { currentcolor = RED; tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*2) { currentcolor = YELLOW; tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*3) { currentcolor = GREEN; tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*4) { currentcolor = CYAN; tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*5) { currentcolor = BLUE; tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE*6) { currentcolor = MAGENTA; tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE); } if (oldcolor != currentcolor) { if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); } } if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); } } }