ansh2919
Published © GPL3+

Beginner’s Guide to Run TFT LCD Displays

Here, you will learn how to use TFT LCDs with Arduino.

BeginnerFull instructions provided8,124
Beginner’s Guide to Run TFT LCD Displays

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
TFT Touchscreen, 320x240
TFT Touchscreen, 320x240
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Basics

Arduino
#include <SPI.h>
#include "Adafruit_GFX.h" // Core Graphics Library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>

// 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

void setup() {
  uint16_t ID = tft.readID();
  tft.begin(ID);
  tft.fillScreen(BLACK);
}

void loop() {
  //Drawing Pixel
  tft.drawPixel(239, 319, WHITE);

  //Drawing Line
  tft.drawLine(50, 60, 70, 80, WHITE);

  //Drawing Rectangle
  tft.drawRect(50, 60, 70, 80, WHITE);

  //Drawing Circle
  tft.drawCircle(100, 100, 100, WHITE);

  //Drawing Rounded Rectangles
  tft.drawRoundRect(100, 100, 40, 90, 80, WHITE);

  //Drawing Triangles
  tft.drawTriangle(100, 100, 40, 200, 180, 210, WHITE);

  //Text and Character
  tft.drawChar(120, 160, 'A', WHITE, BLACK, 2);
  tft.setCursor(20, 160);
  tft.setTextColor(WHITE);
  tft.setTextColor(WHITE, BLACK);
  tft.setTextSize(2);
  tft.write('c');
  tft.print("www.dayalsoft.com");
  tft.println("www.dayalsoft.com");

  //Set Rotation
  tft.setRotation(1);
  tft.drawChar(120, 160, 'A', WHITE, BLACK, 2);

  //Using Fonts
  tft.setFont(&FreeMonoBoldOblique12pt7b);
  tft.drawChar(120, 160, 'A', WHITE, BLACK, 2);
}

Effects

Arduino
#include "Adafruit_GFX.h" //Core graphics library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

// Colors
#define	BLACK 0x0000
#define WHITE 0xFFFF

void setup() {
  uint16_t ID = tft.readID();
  tft.begin(ID);
  tft.fillScreen(BLACK);
}

float i = 0;
int color = WHITE;

void loop() {
  i += 5;
  if (i > 100) {
    i = 0;
    if (color == WHITE) {
      color = BLACK;
    } else {
      color = WHITE;
    }
  }
  tft.drawCircle(240 / 2, 320 / 2, i, color);
}

Credits

ansh2919

ansh2919

1 project • 7 followers

Comments