//Code By A.Tedds. //Using Adafruit Library Files. Thank you. //Usage of tft.drawRect(start position width 0-240,Start position Height 0-320,size 0-240,size 0-320, Color) //#define DEBUG // Gives stats on serial display. #include // Core graphics library #include // Hardware-specific library #define LCD_CS A3 // Chip Select goes to Analog 3 #define LCD_CD A2 // Command/Data goes to Analog 2 #define LCD_WR A1 // LCD Write goes to Analog 1 #define LCD_RD A0 // LCD Read goes to Analog 0 #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin // Assign human-readable names to some common 16-bit color values: // With Changes for Graphic color inversion !! #define BLACK 0xFFFF #define BLUE 0xFFE0 #define GREEN 0xF81F #define CYAN 0xF800 #define GRAY1 0x8410 #define RED 0x07FF //#define BRIGHT_RED 0x???? #define ORANGE 0xFD20 #define GREENYELLOW 0xAFE5 #define DARKGREEN 0x03E0 #define GRAY2 0x4208 #define MAGENTA 0x07E0 #define YELLOW 0x001F #define WHITE 0x0000 Adafruit_ILI9341_8bit_AS tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); void setup(void) { Serial.begin(9600); Serial.println("8 Bit LCD test!"); tft.reset(); delay(10); tft.begin(0x9341); tft.fillScreen(BLACK); } void loop(void) { testtext(YELLOW); //Text Color delay(4000); testfillrects(BLUE,RED);//Color1,Color2 testFillRoundRect(); testRoundRect(); testtriangles(); testfilltriangles(); testdrawcircles(20,RED);//Size and Color testfillcircles(20,GREEN);//size and color testBars(); testlines(60); } void testFillRoundRect() { tft.fillScreen(BLACK); for (uint16_t x=tft.width(); x > 20 ; x-=6) { tft.fillRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.color565(0, x, 0)); } } void testRoundRect() { tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width(); x+=6) { tft.drawRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.color565(x, 0, 0)); } } void testtriangles() { tft.fillScreen(BLACK); for (uint16_t i=0; i10; i-=5) { tft.fillTriangle(tft.width()/2, tft.height()/2-i, tft.width()/2-i, tft.height()/2+i, tft.width()/2+i, tft.height()/2+i, tft.color565(0, i, i)); tft.drawTriangle(tft.width()/2, tft.height()/2-i, tft.width()/2-i, tft.height()/2+i, tft.width()/2+i, tft.height()/2+i, tft.color565(i, i, 0)); } } void testtext(uint16_t color) { tft.fillScreen(BLACK); tft.setCursor(10, 10); tft.setTextColor(color); tft.setTextSize(3); tft.println("Hello World!"); // tft.setTextSize(3); //tft.println(1234.56); //tft.setTextSize(3); //tft.println(0xDEADBEEF, HEX); } void testfillcircles(uint8_t radius, uint16_t color) { for (uint16_t x=radius; x < tft.width(); x+=radius*2) { for (uint16_t y=radius; y < tft.height(); y+=radius*2) { tft.fillCircle(x, y, radius, color); } } } void testdrawcircles(uint8_t radius, uint16_t color) { for (uint16_t x=0; x < tft.width()+radius; x+=radius*2) { for (uint16_t y=0; y < tft.height()+radius; y+=radius*2) { tft.drawCircle(x, y, radius, color); } } } void testfillrects(uint16_t color1, uint16_t color2) { tft.fillScreen(BLACK); for (uint16_t x=tft.width()-1; x > 6; x-=6) { //Serial.println(x, DEC); tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1); tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2); } } void testdrawrects(uint16_t color) { tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width(); x+=6) { tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color); } } void testfastlines(uint16_t color1, uint16_t color2) { tft.fillScreen(BLACK); for (uint16_t y=0; y < tft.height(); y+=5) { tft.drawFastHLine(0, y, tft.width(), color1); } for (uint16_t x=0; x < tft.width(); x+=5) { tft.drawFastVLine(x, 0, tft.height(), color2); } } void testlines(uint16_t color) { tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, 0, x, tft.height()-1, color); } for (uint16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, 0, tft.width()-1, y, color); } tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color); } for (uint16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, 0, 0, y, color); } tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, tft.height()-1, x, 0, color); } for (uint16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, tft.height()-1, tft.width()-1, y, color); } tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color); } for (uint16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color); } } void testBars() { tft.fillScreen(BLACK); tft.fillRect(0, 0, 239, 40,BLACK); tft.fillRect(0, 40, 239, 40,BLUE); tft.fillRect(0, 80, 239, 40,RED); tft.fillRect(0, 120, 239, 40,MAGENTA); tft.fillRect(0, 160, 239, 40,GREEN); tft.fillRect(0, 200, 239, 40,CYAN); tft.fillRect(0, 240, 239, 40,YELLOW); tft.fillRect(0, 280, 239, 40,WHITE); delay(2000); }