Components and supplies
TFT Touchscreen, 320x240
USB-A to Mini-USB Cable
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
Code for displaying text.
c_cpp
1#include <Adafruit_GFX.h> 2#include <MCUFRIEND_kbv.h> 3 4#define BLACK 0x0000 5#define RED 0xF800 6#define WHITE 0xFFFF 7 8MCUFRIEND_kbv tft; 9 10void setup() { 11 // put your setup code here, to run once: 12 uint16_t ID = tft.readID(); 13 tft.begin(ID); 14 tft.fillScreen(BLACK); 15 tft.setCursor(0,0); 16 tft.setTextSize(3); 17 tft.setTextColor(WHITE); 18 tft.print("my first project with tft -"); 19 20} 21 22void loop() { 23 // put your main code here, to run repeatedly: 24 tft.setCursor(0,70); 25 tft.setTextSize(2); 26 tft.setTextColor(RED); 27 tft.print("welcome to the world of arduino and display , myself Aryan Kurkure who loves arduino and game programming very much. This is why I have my own youtube channel in which I share my arduino projects and games made by me , isn't it amazing !"); 28 29} 30
Code for displaying graphics
c_cpp
1#include <Adafruit_GFX.h> 2#include <MCUFRIEND_kbv.h> 3 4#define 5 BLACK 0x0000 6#define BLUE 0x001F 7#define RED 0xF800 8#define 9 GREEN 0x07E0 10#define CYAN 0x07FF 11#define MAGENTA 0xF81F 12#define YELLOW 13 0xFFE0 14#define WHITE 0xFFFF 15 16MCUFRIEND_kbv tft; 17 18int delayPeriod; 19 20void 21 setup() { 22 // put your setup code here, to run once: 23 uint16_t ID=tft.readID(); 24 25 tft.begin(ID); 26 27} 28 29void loop() { 30 // put your main code here, 31 to run repeatedly: 32 tft.fillScreen(BLACK); 33 tft.fillRect(11,11,298,48,RED); 34 35 tft.drawRect(10,10,300,50,YELLOW); 36 tft.setCursor(25,25); 37 tft.setTextColor(WHITE); 38 39 tft.setTextSize(2); 40 tft.println("Welcome to tutorial 2-"); 41 for(int 42 i=65;i<500;i+=7){ 43 tft.drawLine(0,240,100,i,CYAN); 44 delay(100); 45 46 } 47 for(int i=60;i>5;i-=3){ 48 tft.drawCircle(210,140,i,GREEN); 49 delay(30); 50 51 } 52 for(int i=200;i>70;i-=7){ 53 tft.drawRect(120,220,i,i,YELLOW); 54 55 delay(30); 56 } 57 tft.setCursor(122.5,255); 58 tft.setTextSize(2); 59 60 tft.println("Enjoy!"); 61 62 delay(1500); 63 64 tft.fillScreen(WHITE); 65 66 67 tft.fillRect(10,10,300,60,YELLOW); 68 tft.setCursor(40,30); 69 tft.setTextSize(2); 70 71 tft.setTextColor(MAGENTA); 72 tft.println("Thanks for watching !"); 73 74 75 for(int i=0;i<80;i+=5){ 76 tft.drawTriangle( 77 160,70+i*2, 78 79 30+i,320-i, 80 290-i,320-i, 81 RED 82 ); 83 84 delay(200); 85 } 86 87 tft.fillRect(7,350,300,70,YELLOW); 88 tft.setCursor(10,370); 89 90 tft.setTextSize(2); 91 tft.setTextColor(BLACK); 92 tft.print("Repeating myself 93 in some seconds"); 94 for(delayPeriod=4;delayPeriod>0;delayPeriod-=1){ 95 tft.print("."); 96 97 delay(1000); 98 99 } 100 101} 102
Code for displaying graphics
c_cpp
1#include <Adafruit_GFX.h> 2#include <MCUFRIEND_kbv.h> 3 4#define BLACK 0x0000 5#define BLUE 0x001F 6#define RED 0xF800 7#define GREEN 0x07E0 8#define CYAN 0x07FF 9#define MAGENTA 0xF81F 10#define YELLOW 0xFFE0 11#define WHITE 0xFFFF 12 13MCUFRIEND_kbv tft; 14 15int delayPeriod; 16 17void setup() { 18 // put your setup code here, to run once: 19 uint16_t ID=tft.readID(); 20 tft.begin(ID); 21 22} 23 24void loop() { 25 // put your main code here, to run repeatedly: 26 tft.fillScreen(BLACK); 27 tft.fillRect(11,11,298,48,RED); 28 tft.drawRect(10,10,300,50,YELLOW); 29 tft.setCursor(25,25); 30 tft.setTextColor(WHITE); 31 tft.setTextSize(2); 32 tft.println("Welcome to tutorial 2-"); 33 for(int i=65;i<500;i+=7){ 34 tft.drawLine(0,240,100,i,CYAN); 35 delay(100); 36 } 37 for(int i=60;i>5;i-=3){ 38 tft.drawCircle(210,140,i,GREEN); 39 delay(30); 40 } 41 for(int i=200;i>70;i-=7){ 42 tft.drawRect(120,220,i,i,YELLOW); 43 delay(30); 44 } 45 tft.setCursor(122.5,255); 46 tft.setTextSize(2); 47 tft.println("Enjoy!"); 48 49 delay(1500); 50 51 tft.fillScreen(WHITE); 52 53 tft.fillRect(10,10,300,60,YELLOW); 54 tft.setCursor(40,30); 55 tft.setTextSize(2); 56 tft.setTextColor(MAGENTA); 57 tft.println("Thanks for watching !"); 58 59 for(int i=0;i<80;i+=5){ 60 tft.drawTriangle( 61 160,70+i*2, 62 30+i,320-i, 63 290-i,320-i, 64 RED 65 ); 66 delay(200); 67 } 68 69 tft.fillRect(7,350,300,70,YELLOW); 70 tft.setCursor(10,370); 71 tft.setTextSize(2); 72 tft.setTextColor(BLACK); 73 tft.print("Repeating myself in some seconds"); 74 for(delayPeriod=4;delayPeriod>0;delayPeriod-=1){ 75 tft.print("."); 76 delay(1000); 77 78 } 79 80} 81
Code for displaying text.
c_cpp
1#include <Adafruit_GFX.h> 2#include <MCUFRIEND_kbv.h> 3 4#define BLACK 0x0000 5#define RED 0xF800 6#define WHITE 0xFFFF 7 8MCUFRIEND_kbv tft; 9 10void setup() { 11 // put your setup code here, to run once: 12 uint16_t ID = tft.readID(); 13 tft.begin(ID); 14 tft.fillScreen(BLACK); 15 tft.setCursor(0,0); 16 tft.setTextSize(3); 17 tft.setTextColor(WHITE); 18 tft.print("my first project with tft -"); 19 20} 21 22void loop() { 23 // put your main code here, to run repeatedly: 24 tft.setCursor(0,70); 25 tft.setTextSize(2); 26 tft.setTextColor(RED); 27 tft.print("welcome to the world of arduino and display , myself Aryan Kurkure who loves arduino and game programming very much. This is why I have my own youtube channel in which I share my arduino projects and games made by me , isn't it amazing !"); 28 29} 30
Downloadable files
connection for tft lcd shield
connection for tft lcd shield
Comments
Only logged in users can leave comments