The TFT Screen is a touch screen. The screen that we will use a composed of 320p per 240p. Using this screen is pretty simple : you just have to design forms and text using functions, such as :
tft.reset();
tft.begin(0x9341);
tft.fillScreen(BLACK);
tft.setRotation(1);
These functions reset the screen, color the screen in black, and set the screen into the landscape mode.
tft.setCursor(5, 5);
It set the cursor.
tft.setTextColor(WHITE);
It defines the color of the text.
tft.setTextSize(1);
It defines the text size.
tft.println("Kittens are cute !");
It prints the text ( after saying that the text have a color, a size and a cursor ).
tft.drawLine(x1, y1, x2, y2, color);
It draws a pixel ( x/y : coordinates of the pixel and color ).
tft.drawPixel(x, y, color);
It draws a line ( x1/y1 : first point coordinates ; x2/y2 : second point coordinates and color.
tft.fillCircle(x, y, radius, color);
It draws a filled circle with the color that we use ( x/y : center coordinates ; Radius and color ).
tft.drawCircle(x, y, radius, color);
It draws a simple circle ( same characteristics than the filled circle but this time the circle isn't filled ).
tft.drawRect(x, y, x2, y2, color);
It draws a simple rectangle ( x/y : one point of the rectangle ; x2 = x1+length of the rectangle / y2 = y1 + width of the rectangle and color ).
tft.fillRect(x, y, x2, y2, color);
It draws a filled rectangle ( same characteristics than the simple rectangle but the rectangle is filled ).
tft.drawRoundRect(x, y, x2, y2, c, color);
It draws a rectangle with curved corners ( same characteristics than the rectangle but here, c is the number of pixel that curved corners of the rectangle ).
tft.fillRoundRect(x, y, x2, y2, c, color);
Its draws a filled rectangle with curved corners ( same characteristics than the rounded rectangle ).
Available colors :
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
CS, CD, WR, RD and RST pins definition :
For Arduino Mega/Uno :
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
LibrariesIn this project we will use 2 libraries : Elegoo GFX and Elegoo TFTLCD.
Libraries can be download on the "Enclosures and Customs parts" area.
Code#include <Elegoo_GFX.h>
#include <Elegoo_TFTLCD.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup(void) {
tft.reset();
tft.begin(0x9341);
tft.fillScreen(BLACK);
tft.setRotation(1);
tft.setCursor(5, 5);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.println("Potentiometer value :");
tft.drawRect(155, 5, 15, 230, WHITE);
tft.drawLine(170, 230, 175, 230, WHITE);
tft.drawLine(170, 221, 175, 221, WHITE);
tft.drawLine(170, 212, 175, 212, WHITE);
tft.drawLine(170, 203, 175, 203, WHITE);
tft.drawLine(170, 194, 175, 194, WHITE);
tft.drawLine(170, 185, 175, 185, WHITE);
tft.drawLine(170, 176, 175, 176, WHITE);
tft.drawLine(170, 167, 175, 167, WHITE);
tft.drawLine(170, 158, 175, 158, WHITE);
tft.drawLine(170, 149, 175, 149, WHITE);
tft.drawLine(170, 140, 175, 140, WHITE);
tft.drawLine(170, 131, 175, 131, WHITE);
tft.drawLine(170, 122, 175, 122, WHITE);
tft.drawLine(170, 113, 175, 113, WHITE);
tft.drawLine(170, 104, 175, 104, WHITE);
tft.drawLine(170, 95, 175, 95, WHITE);
tft.drawLine(170, 86, 175, 86, WHITE);
tft.drawLine(170, 77, 175, 77, WHITE);
tft.drawLine(170, 68, 175, 68, WHITE);
tft.drawLine(170, 59, 175, 59, WHITE);
tft.drawLine(170, 50, 175, 50, WHITE);
tft.drawLine(170, 41, 175, 41, WHITE);
tft.drawLine(170, 32, 175, 32, WHITE);
tft.drawLine(170, 23, 175, 23, WHITE);
tft.drawLine(170, 14, 175, 14, WHITE);
}
void loop(void) {
int x = analogRead(A15);
int b = map(x, 0,1024,10,200);
unsigned long start = micros();
tft.setCursor(15, 45);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println(x);
tft.fillRect(160, b, 5, 30, BLUE);
delay(20);
tft.fillRect(160, b, 5, 30, BLACK);
tft.fillRect(15, 45, 50, 55, BLACK);
return micros() - start;
}
ConnectionsThis screen is a shield so you just have to plug it on the Arduino Mega by following pins definiton provided above.
Comments