Components and supplies
TFT Touchscreen, 320x240
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
Basics
arduino
1#include <SPI.h> 2#include "Adafruit_GFX.h" // Core Graphics Library 3#include <MCUFRIEND_kbv.h> 4MCUFRIEND_kbv tft; 5#include <Fonts/FreeMonoBoldOblique12pt7b.h> 6#include <Fonts/FreeSerif9pt7b.h> 7 8// Colors 9#define BLACK 0x0000 10#define BLUE 0x001F 11#define RED 0xF800 12#define GREEN 0x07E0 13#define CYAN 0x07FF 14#define MAGENTA 0xF81F 15#define YELLOW 0xFFE0 16#define WHITE 0xFFFF 17 18void setup() { 19 uint16_t ID = tft.readID(); 20 tft.begin(ID); 21 tft.fillScreen(BLACK); 22} 23 24void loop() { 25 //Drawing Pixel 26 tft.drawPixel(239, 319, WHITE); 27 28 //Drawing Line 29 tft.drawLine(50, 60, 70, 80, WHITE); 30 31 //Drawing Rectangle 32 tft.drawRect(50, 60, 70, 80, WHITE); 33 34 //Drawing Circle 35 tft.drawCircle(100, 100, 100, WHITE); 36 37 //Drawing Rounded Rectangles 38 tft.drawRoundRect(100, 100, 40, 90, 80, WHITE); 39 40 //Drawing Triangles 41 tft.drawTriangle(100, 100, 40, 200, 180, 210, WHITE); 42 43 //Text and Character 44 tft.drawChar(120, 160, 'A', WHITE, BLACK, 2); 45 tft.setCursor(20, 160); 46 tft.setTextColor(WHITE); 47 tft.setTextColor(WHITE, BLACK); 48 tft.setTextSize(2); 49 tft.write('c'); 50 tft.print("www.dayalsoft.com"); 51 tft.println("www.dayalsoft.com"); 52 53 //Set Rotation 54 tft.setRotation(1); 55 tft.drawChar(120, 160, 'A', WHITE, BLACK, 2); 56 57 //Using Fonts 58 tft.setFont(&FreeMonoBoldOblique12pt7b); 59 tft.drawChar(120, 160, 'A', WHITE, BLACK, 2); 60}
Effects
arduino
1#include "Adafruit_GFX.h" //Core graphics library 2#include <MCUFRIEND_kbv.h> 3MCUFRIEND_kbv tft; 4 5// Colors 6#define BLACK 0x0000 7#define WHITE 0xFFFF 8 9void setup() { 10 uint16_t ID = tft.readID(); 11 tft.begin(ID); 12 tft.fillScreen(BLACK); 13} 14 15float i = 0; 16int color = WHITE; 17 18void loop() { 19 i += 5; 20 if (i > 100) { 21 i = 0; 22 if (color == WHITE) { 23 color = BLACK; 24 } else { 25 color = WHITE; 26 } 27 } 28 tft.drawCircle(240 / 2, 320 / 2, i, color); 29}
Basics
arduino
1#include <SPI.h> 2#include "Adafruit_GFX.h" // Core Graphics Library 3#include 4 <MCUFRIEND_kbv.h> 5MCUFRIEND_kbv tft; 6#include <Fonts/FreeMonoBoldOblique12pt7b.h> 7#include 8 <Fonts/FreeSerif9pt7b.h> 9 10// Colors 11#define BLACK 0x0000 12#define BLUE 13 0x001F 14#define RED 0xF800 15#define GREEN 0x07E0 16#define CYAN 17 0x07FF 18#define MAGENTA 0xF81F 19#define YELLOW 0xFFE0 20#define WHITE 21 0xFFFF 22 23void setup() { 24 uint16_t ID = tft.readID(); 25 tft.begin(ID); 26 27 tft.fillScreen(BLACK); 28} 29 30void loop() { 31 //Drawing Pixel 32 tft.drawPixel(239, 33 319, WHITE); 34 35 //Drawing Line 36 tft.drawLine(50, 60, 70, 80, WHITE); 37 38 39 //Drawing Rectangle 40 tft.drawRect(50, 60, 70, 80, WHITE); 41 42 //Drawing 43 Circle 44 tft.drawCircle(100, 100, 100, WHITE); 45 46 //Drawing Rounded Rectangles 47 48 tft.drawRoundRect(100, 100, 40, 90, 80, WHITE); 49 50 //Drawing Triangles 51 52 tft.drawTriangle(100, 100, 40, 200, 180, 210, WHITE); 53 54 //Text and Character 55 56 tft.drawChar(120, 160, 'A', WHITE, BLACK, 2); 57 tft.setCursor(20, 160); 58 59 tft.setTextColor(WHITE); 60 tft.setTextColor(WHITE, BLACK); 61 tft.setTextSize(2); 62 63 tft.write('c'); 64 tft.print("www.dayalsoft.com"); 65 tft.println("www.dayalsoft.com"); 66 67 68 //Set Rotation 69 tft.setRotation(1); 70 tft.drawChar(120, 160, 'A', WHITE, 71 BLACK, 2); 72 73 //Using Fonts 74 tft.setFont(&FreeMonoBoldOblique12pt7b); 75 76 tft.drawChar(120, 160, 'A', WHITE, BLACK, 2); 77}
Comments
Only logged in users can leave comments
ansh2919
2 Followers
•0 Projects
4
0