// Demo based on: // UTFT_Demo_320x240 by Henning Karlsen // web: http://www.henningkarlsen.com/electronics // /* This sketch uses the GLCD and font 2 only. Disable other fonts to make the sketch fit in an UNO! Make sure all the required fonts are loaded by editting the User_Setup.h file in the TFT_eSPI library folder. The library uses the hardware SPI pins only: For UNO, Nano, Micro Pro ATmega328 based processors MOSI = pin 11, SCK = pin 13 For Mega: MOSI = pin 51, SCK = pin 52 The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST) signal lines to the TFT must also be defined in the library User_Setup.h file. Sugested TFT connections for UNO and Atmega328 based boards sclk 13 // Don't change, this is the hardware SPI SCLK line mosi 11 // Don't change, this is the hardware SPI MOSI line cs 10 // Chip select for TFT display dc 9 // Data/command line rst 7 // Reset, you could connect this to the Arduino reset pin Suggested TFT connections for the MEGA and ATmega2560 based boards sclk 52 // Don't change, this is the hardware SPI SCLK line mosi 51 // Don't change, this is the hardware SPI MOSI line cs 47 // TFT chip select line dc 48 // TFT data/command line rst 44 // you could alternatively connect this to the Arduino reset ######################################################################### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ###### ######################################################################### */ #include // Graphics and font library for ST7735 driver chip #include TFT_eSPI myGLCD = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h #define DELAY 500 #define TFT_GREY 0x7BEF #define TFT_W 160 #define TFT_H 128 unsigned long runTime = 0; void setup() { randomSeed(analogRead(A0)); pinMode(7, OUTPUT); digitalWrite(7, LOW); delay(10); digitalWrite(7, HIGH); // Setup the LCD myGLCD.init(); myGLCD.setRotation(1); } void loop() { randomSeed(millis()); //randomSeed(1234); // This ensure test is repeatable with exact same draws each loop int buf[TFT_W-2]; int x, x2; int y, y2; int r; runTime = millis(); // Clear the screen and draw the frame myGLCD.fillScreen(TFT_BLACK); myGLCD.fillRect(0, 0, TFT_W-1, 14,TFT_RED); myGLCD.fillRect(0, TFT_H-14, TFT_W-1, 14,TFT_GREY); myGLCD.setTextColor(TFT_BLACK,TFT_RED); myGLCD.drawCentreString("* TFT_S6D02A1 *", TFT_W/2, 4, 1); myGLCD.setTextColor(TFT_YELLOW,TFT_GREY); myGLCD.drawCentreString("Adapted by Bodmer", TFT_W/2, TFT_H-12,1); myGLCD.drawRect(0, 14, TFT_W-1, TFT_H-28, TFT_BLUE); // Draw crosshairs myGLCD.drawLine(TFT_W/2-1, 15, TFT_W/2-1, TFT_H-16,TFT_BLUE); myGLCD.drawLine(1, TFT_H/2-1, TFT_W-2, TFT_H/2-1,TFT_BLUE); for (int i=9; iTFT_W-2) { if ((x==TFT_W/2-1)||(buf[x-1]==TFT_H/2-1)) col = TFT_BLUE; else myGLCD.drawPixel(x,buf[x-1],TFT_BLACK); } y=TFT_H/2 +(sin(((i*2.2)*3.14)/180)*(49-(i / 100))); myGLCD.drawPixel(x,y,TFT_BLUE); buf[x-1]=y; } delay(DELAY); myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); // Draw some filled rectangles for (int i=1; i<6; i++) { switch (i) { case 1: col = TFT_MAGENTA; break; case 2: col = TFT_RED; break; case 3: col = TFT_GREEN; break; case 4: col = TFT_BLUE; break; case 5: col = TFT_YELLOW; break; } myGLCD.fillRect(30+(i*10), 20+(i*10), 30, 30,col); } delay(DELAY); myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); // Draw some filled, rounded rectangles for (int i=1; i<6; i++) { switch (i) { case 1: col = TFT_MAGENTA; break; case 2: col = TFT_RED; break; case 3: col = TFT_GREEN; break; case 4: col = TFT_BLUE; break; case 5: col = TFT_YELLOW; break; } myGLCD.fillRoundRect(TFT_W/2+20-(i*10), 20+(i*10), 30,30, 3,col); } delay(DELAY); myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); // Draw some filled circles for (int i=1; i<6; i++) { switch (i) { case 1: col = TFT_MAGENTA; break; case 2: col = TFT_RED; break; case 3: col = TFT_GREEN; break; case 4: col = TFT_BLUE; break; case 5: col = TFT_YELLOW; break; } myGLCD.fillCircle(45+(i*10),30+(i*10), 15,col); } delay(DELAY); myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); // Draw some lines in a pattern for (int i=15; i15; i-=5) { myGLCD.drawLine(TFT_W-3, i, (i*1.44)-11, 15,TFT_RED); } for (int i=TFT_H-17; i>15; i-=5) { myGLCD.drawLine(1, i, TFT_W+11-(i*1.44), 15,TFT_CYAN); } for (int i=15; i