چند مثال از راه اندازی Lcd tft 2.4 با آردوینو

به نام خدا

این پروژه توضیح زیادی نداره چندتا پروژه جالب و دوس داشتنی با اردینو و LCD TFT 2.4  هست کد هاشم تقریبا قابل فهمه که چی به چیه هرجاییشم نفهمیدید در خدمتم.

اتصال LCD به آردوینو

شیلد ال سی دی برای اردینو طراحی شده مستقیم رو اردینو قرار میگیره پس نیاز به  شماتیک نیست !

کتابخونه ها را از اینجا دانلود کنید.

دانلود کتابخانه های مورد نیاز

رمز فایل ها: melec.ir

پروژه اول : نمایش انیمیشن بر روی Lcd tft 2.4 با آردوینو

 

#include <Adafruit_GFX.h>
//#include <Adafruit_TFTLCD.h> // this header is not needed
#include <UTFTGLUE.h> // class methods are in here
//UTFTGLUE myGLCD; // use for default shield
//UTFTGLUE myGLCD(0x9320,A2,A1,A3,A4,A0);
//UTFTGLUE myGLCD(0x9325,A2,A1,A3,A4,A0);
//UTFTGLUE myGLCD(0x7783,A2,A1,A3,A4,A0);
//UTFTGLUE myGLCD(0x1289,A1,A2,A0,0,A3); // this might choose the pins
UTFTGLUE myGLCD(0x0154,A2,A1,A3,A4,A0);

/*
#include <UTFT.h>
//#include <SD.h>
//UTFT myGLCD(ILI9325C,A2,A1,A3,A4); // Remember to change the model parameter to suit your display module!
//UTFT myGLCD(ILI9325D_8,A2,A1,A3,A4); // Remember to change the model parameter to suit your display module!
UTFT myGLCD(SSD1289_8,A1,A2,A0,A3); // Remember to change the model parameter to suit your display module!
*/

// Uncomment the next line for Arduino 2009/Uno
// UTFT(byte model, int RS, int WR,int CS,int RD)
//UTFT myGLCD(ILI9325C,A2,A1,A3,A0); // Remember to change the model parameter to suit your display module!
//Adafruit_UTFT myGLCD;

// Declare which fonts we will be using
extern uint8_t SmallFont[];

void setup()
{
randomSeed(analogRead(0));
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);

// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
}

void loop()
{
int buf[318];
int x, x2;
int y, y2;
int r;

// Clear the screen and draw the frame
myGLCD.clrScr();

myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 319, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 226, 319, 239);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
myGLCD.setBackColor(64, 64, 64);
myGLCD.setColor(255,255,0);
myGLCD.print("<http://electronics.henningkarlsen.com>", CENTER, 227);

myGLCD.setColor(0, 0, 255);
myGLCD.drawRect(0, 14, 319, 225);

// Draw crosshairs
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(159, 15, 159, 224);
myGLCD.drawLine(1, 119, 318, 119);
for (int i=9; i<310; i+=10)
myGLCD.drawLine(i, 117, i, 121);
for (int i=19; i<220; i+=10)
myGLCD.drawLine(157, i, 161, i);

// Draw sin-, cos- and tan-lines
myGLCD.setColor(0,255,255);
myGLCD.print("Sin", 5, 15);
for (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
}

myGLCD.setColor(255,0,0);
myGLCD.print("Cos", 5, 27);
for (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
}

myGLCD.setColor(255,255,0);
myGLCD.print("Tan", 5, 39);
for (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(159, 15, 159, 224);
myGLCD.drawLine(1, 119, 318, 119);

// Draw a moving sinewave
x=1;
for (int i=1; i<(318*20); i++)
{
x++;
if (x==319)
x=1;
if (i>319)
{
if ((x==159)||(buf[x-1]==119))
myGLCD.setColor(0,0,255);
else
myGLCD.setColor(0,0,0);
myGLCD.drawPixel(x,buf[x-1]);
}
myGLCD.setColor(0,255,255);
y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
myGLCD.drawPixel(x,y);
buf[x-1]=y;
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

// Draw some filled rectangles
for (int i=1; i<6; i++)
{
switch (i)
{
case 1:
myGLCD.setColor(255,0,255);
break;
case 2:
myGLCD.setColor(255,0,0);
break;
case 3:
myGLCD.setColor(0,255,0);
break;
case 4:
myGLCD.setColor(0,0,255);
break;
case 5:
myGLCD.setColor(255,255,0);
break;
}
myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

// Draw some filled, rounded rectangles
for (int i=1; i<6; i++)
{
switch (i)
{
case 1:
myGLCD.setColor(255,0,255);
break;
case 2:
myGLCD.setColor(255,0,0);
break;
case 3:
myGLCD.setColor(0,255,0);
break;
case 4:
myGLCD.setColor(0,0,255);
break;
case 5:
myGLCD.setColor(255,255,0);
break;
}
myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

// Draw some filled circles
for (int i=1; i<6; i++)
{
switch (i)
{
case 1:
myGLCD.setColor(255,0,255);
break;
case 2:
myGLCD.setColor(255,0,0);
break;
case 3:
myGLCD.setColor(0,255,0);
break;
case 4:
myGLCD.setColor(0,0,255);
break;
case 5:
myGLCD.setColor(255,255,0);
break;
}
myGLCD.fillCircle(100+(i*20),60+(i*20), 30);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

// Draw some lines in a pattern
myGLCD.setColor (255,0,0);
for (int i=15; i<224; i+=5)
{
myGLCD.drawLine(1, i, (i*1.44)-10, 224);
}
myGLCD.setColor (255,0,0);
for (int i=224; i>15; i-=5)
{
myGLCD.drawLine(318, i, (i*1.44)-11, 15);
}
myGLCD.setColor (0,255,255);
for (int i=224; i>15; i-=5)
{
myGLCD.drawLine(1, i, 331-(i*1.44), 15);
}
myGLCD.setColor (0,255,255);
for (int i=15; i<224; i+=5)
{
myGLCD.drawLine(318, i, 330-(i*1.44), 224);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,225);

// Draw some random circles
for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=32+random(256);
y=45+random(146);
r=random(30);
myGLCD.drawCircle(x, y, r);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

// Draw some random rectangles
for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=2+random(316);
y=16+random(207);
x2=2+random(316);
y2=16+random(207);
myGLCD.drawRect(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

// Draw some random rounded rectangles
for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=2+random(316);
y=16+random(207);
x2=2+random(316);
y2=16+random(207);
myGLCD.drawRoundRect(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=2+random(316);
y=16+random(209);
x2=2+random(316);
y2=16+random(209);
myGLCD.drawLine(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,318,224);

for (int i=0; i<10000; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
myGLCD.drawPixel(2+random(316), 16+random(209));
}

delay(2000);

myGLCD.fillScr(0, 0, 255);
myGLCD.setColor(255, 0, 0);
myGLCD.fillRoundRect(80, 70, 239, 169);

myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("That's it!", CENTER, 93);
myGLCD.print("Restarting in a", CENTER, 119);
myGLCD.print("few seconds...", CENTER, 132);

myGLCD.setColor(0, 255, 0);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print("Runtime: (msecs)", CENTER, 210);
myGLCD.printNumI(millis(), CENTER, 225);

delay (10000);
}


پروژه دوم :رسم اشکال هندسی روی TFT LCD با آردوینو

#include <SPI.h> // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
//#include <Adafruit_TFTLCD.h>
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
void setup(void);
void loop(void);
unsigned long testFillScreen();
unsigned long testText();
unsigned long testLines(uint16_t color);
unsigned long testFastLines(uint16_t color1, uint16_t color2);
unsigned long testRects(uint16_t color);
unsigned long testFilledRects(uint16_t color1, uint16_t color2);
unsigned long testFilledCircles(uint8_t radius, uint16_t color);
unsigned long testCircles(uint8_t radius, uint16_t color);
unsigned long testTriangles();
unsigned long testFilledTriangles();
unsigned long testRoundRects();
unsigned long testFilledRoundRects();
void progmemPrint(const char *str);
void progmemPrintln(const char *str);
void runtests(void);
uint16_t g_identifier;
extern const uint8_t hanzi[];
void showhanzi(unsigned int x, unsigned int y, unsigned char index)
{
uint8_t i, j, c, first = 1;
uint8_t *temp = (uint8_t*)hanzi;
uint16_t color;
tft.setAddrWindow(x, y, x + 31, y + 31); //设置区域
temp += index * 128;
for (j = 0; j < 128; j++)
{
c = pgm_read_byte(temp);
for (i = 0; i < 8; i++)
{
if ((c & (1 << i)) != 0)
{
color = RED;
}
else
{
color = BLACK;
}
tft.pushColors(&color, 1, first);
first = 0;
}
temp++;
}
}
void setup(void) {
Serial.begin(9600);
uint32_t when = millis();
// while (!Serial) ; //hangs a Leonardo until you connect a Serial
if (!Serial) delay(5000); //allow some time for Leonardo
Serial.println("Serial took " + String((millis() - when)) + "ms to start");
static uint16_t identifier;
// tft.reset(); //we can't read ID on 9341 until begin()
g_identifier = tft.readID(); //
Serial.print("ID = 0x");
Serial.println(g_identifier, HEX);
if (g_identifier == 0x00D3 || g_identifier == 0xD3D3) g_identifier = 0x9481; // write-only shield
if (g_identifier == 0xFFFF) g_identifier = 0x9341; // serial
// g_identifier = 0x9329; // force ID
tft.begin(g_identifier);
}
#if defined(MCUFRIEND_KBV_H_)
uint16_t scrollbuf[320]; // my biggest screen is 320x480
#define READGRAM(x, y, buf, w, h) tft.readGRAM(x, y, buf, w, h)
#else
uint16_t scrollbuf[320]; // Adafruit only does 240x320
// Adafruit can read a block by one pixel at a time
int16_t READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
{
uint16_t *p;
for (int row = 0; row < h; row++) {
p = block + row * w;
for (int col = 0; col < w; col++) {
*p++ = tft.readPixel(x + col, y + row);
}
}
}
#endif
void windowScroll(int16_t x, int16_t y, int16_t wid, int16_t ht, int16_t dx, int16_t dy, uint16_t *buf)
{
if (dx) for (int16_t row = 0; row < ht; row++) {
READGRAM(x, y + row, buf, wid, 1);
tft.setAddrWindow(x, y + row, x + wid - 1, y + row);
tft.pushColors(buf + dx, wid - dx, 1);
tft.pushColors(buf + 0, dx, 0);
}
if (dy) for (int16_t col = 0; col < wid; col++) {
READGRAM(x + col, y, buf, 1, ht);
tft.setAddrWindow(x + col, y, x + col, y + ht - 1);
tft.pushColors(buf + dy, ht - dy, 1);
tft.pushColors(buf + 0, dy, 0);
}
}
void loop(void) {
uint8_t aspect;
uint16_t pixel;
char *aspectname[] = {
"PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"
};
char *colorname[] = { "BLUE", "GREEN", "RED", "GRAY" };
uint16_t colormask[] = { 0x001F, 0x07E0, 0xF800, 0xFFFF };
uint16_t dx, rgb, n, wid, ht;
tft.setRotation(0);
// for (uint8_t i = 0; i < 2; i++) showhanzi(0, 0, i), delay(1000);
runtests();
delay(2000);
if (tft.height() > 64) {
for (uint8_t cnt = 0; cnt < 4; cnt++) {
aspect = (cnt + 0) & 3;
tft.setRotation(aspect);
wid = tft.width();
ht = tft.height();
testText();
dx = wid / 32;
for (n = 0; n < 32; n++) {
rgb = n * 8;
rgb = tft.color565(rgb, rgb, rgb);
tft.fillRect(n * dx, 48, dx, 64, rgb & colormask[aspect]);
}
tft.setTextSize(2);
tft.setTextColor(colormask[aspect], BLACK);
tft.setCursor(0, 72);
tft.print(colorname[aspect]);
tft.setTextColor(WHITE);
tft.println(" COLOR GRADES");
tft.setTextColor(WHITE, BLACK);
tft.setCursor(0, 184);
tft.println(aspectname[aspect]);
delay(1000);
tft.drawPixel(0, 0, YELLOW);
pixel = tft.readPixel(0, 0);
#if defined(MCUFRIEND_KBV_H_)
extern const uint8_t penguin[];
tft.setAddrWindow(wid - 40 - 40, 20 + 0, wid - 1 - 40, 20 + 39);
tft.pushColors(penguin, 1600, 1);
tft.setTextColor(WHITE, BLACK);
tft.println("VERTICAL SCROLL UP");
uint16_t maxscroll;
if (tft.getRotation() & 1) maxscroll = wid;
else maxscroll = ht;
for (uint16_t i = 1; i <= maxscroll; i++) {
tft.vertScroll(0, maxscroll, i);
delay(10);
}
tft.vertScroll(0, maxscroll, 0);
tft.setCursor(0, 200);
tft.println("VERTICAL SCROLL DN");
for (uint16_t i = 1; i <= maxscroll; i++) {
tft.vertScroll(0, maxscroll, 0 - (int16_t)i);
delay(10);
}
delay(1000);
tft.vertScroll(0, maxscroll, 0);
if ((aspect & 1) == 0) { //Portrait
tft.setCursor(0, 200);
tft.setTextColor(BLUE, BLACK);
tft.println("ONLY THE COLOR BAND");
for (uint16_t i = 1; i <= 64; i++) {
tft.vertScroll(48, 64, i);
delay(20);
}
delay(1000);
tft.vertScroll(0, maxscroll, 0);
}
#endif
tft.setCursor(0, 200);
tft.setTextColor(YELLOW, BLACK);
if (pixel == YELLOW) {
tft.println("Melec.ir ");
#if 0
for (int16_t i = 45, dx = 2, dy = 1; i > 0; i -= dx) {
windowScroll(24, 8, 90, 40, dx, dy, scrollbuf);
}
#else
// scroll a whole width of the screen
n = (wid > 320) ? 320 : wid;
for (int16_t i = n, dx = 4, dy = 0; i > 0; i -= dx) {
windowScroll(0, 200, n, 16, dx, dy, scrollbuf);
}
#endif
}
else if (pixel == CYAN)
tft.println("readPixel() reads as BGR");
else if ((pixel & 0xF8F8) == 0xF8F8)
tft.println("readPixel() should be 24-bit");
else {
tft.print("readPixel() reads 0x");
tft.println(pixel, HEX);
}
delay(5000);
}
}
tft.println("INVERT DISPLAY");
tft.invertDisplay(true);
delay(2000);
tft.invertDisplay(false);
}
typedef struct {
PGM_P msg;
uint32_t ms;
} TEST;
TEST result[12];
#define RUNTEST(n, str, test) { result[n].msg = PSTR(str); result[n].ms = test; delay(500); }
void runtests(void)
{
uint8_t i, len = 24, cnt;
uint32_t total;
RUNTEST(0, "FillScreen ", testFillScreen());
RUNTEST(1, "Text ", testText());
RUNTEST(2, "Lines ", testLines(CYAN));
RUNTEST(3, "Horiz/Vert Lines ", testFastLines(RED, BLUE));
RUNTEST(4, "Rectangles (outline) ", testRects(GREEN));
RUNTEST(5, "Rectangles (filled) ", testFilledRects(YELLOW, MAGENTA));
RUNTEST(6, "Circles (filled) ", testFilledCircles(10, MAGENTA));
RUNTEST(7, "Circles (outline) ", testCircles(10, WHITE));
RUNTEST(8, "Triangles (outline) ", testTriangles());
RUNTEST(9, "Triangles (filled) ", testFilledTriangles());
RUNTEST(10, "Rounded rects (outline) ", testRoundRects());
RUNTEST(11, "Rounded rects (filled) ", testFilledRoundRects());
tft.fillScreen(BLACK);
tft.setTextColor(GREEN);
tft.setCursor(0, 0);
uint16_t wid = tft.width();
if (wid > 176) {
tft.setTextSize(2);
#if defined(MCUFRIEND_KBV_H_)
tft.print("MCUFRIEND ");
#if MCUFRIEND_KBV_H_ != 0
tft.print(0.01 * MCUFRIEND_KBV_H_, 1);
#else
tft.print("for");
#endif
tft.println(" UNO");
#else
tft.println("Adafruit-Style Tests");
#endif
} else len = wid / 6 - 8;
tft.setTextSize(1);
total = 0;
for (i = 0; i < 12; i++) {
PGM_P str = result[i].msg;
char c;
if (len > 24) {
if (i < 10) tft.print(" ");
tft.print(i);
tft.print(": ");
}
uint8_t cnt = len;
while ((c = pgm_read_byte(str++)) && cnt--) tft.print(c);
tft.print(" ");
tft.println(result[i].ms);
total += result[i].ms;
}
tft.setTextSize(2);
tft.print("Total:");
tft.print(0.000001 * total);
tft.println("sec");
g_identifier = tft.readID();
tft.print("ID: 0x");
tft.println(tft.readID(), HEX);
tft.print("Reg(00):0x");
tft.println(tft.readReg(0x00), HEX);
tft.print("F_CPU:");
tft.print(0.000001 * F_CPU);
#if defined(__OPTIMIZE_SIZE__)
tft.println("MHz -Os");
#else
tft.println("MHz");
#endif
delay(10000);
}
// Standard Adafruit tests. will adjust to screen size
unsigned long testFillScreen() {
unsigned long start = micros();
tft.fillScreen(BLACK);
tft.fillScreen(RED);
tft.fillScreen(GREEN);
tft.fillScreen(BLUE);
tft.fillScreen(BLACK);
return micros() - start;
}
unsigned long testText() {
unsigned long start;
tft.fillScreen(BLACK);
start = micros();
tft.setCursor(0, 0);
tft.setTextColor(WHITE); tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(YELLOW); tft.setTextSize(2);
tft.println(123.45);
tft.setTextColor(RED); tft.setTextSize(3);
tft.println(0xDEADBEEF, HEX);
tft.println();
tft.setTextColor(GREEN);
tft.setTextSize(5);
tft.println("melec.ir");
tft.setTextSize(2);
tft.println("Ali faramarzi");
tft.setTextSize(1);
tft.println("MCA");
return micros() - start;
}
unsigned long testLines(uint16_t color) {
unsigned long start, t;
int x1, y1, x2, y2,
w = tft.width(),
h = tft.height();
tft.fillScreen(BLACK);
x1 = y1 = 0;
y2 = h - 1;
start = micros();
for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
x2 = w - 1;
for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
t = micros() - start; // fillScreen doesn't count against timing
tft.fillScreen(BLACK);
x1 = w - 1;
y1 = 0;
y2 = h - 1;
start = micros();
for (x2 = 0; x2 < w; x

 

مطلب پیشنهادی:  پروژه مدار دماسنج دیجیتال با استفاده از آردوینو

پروژه سوم: نمایش ساعت از روی کامپیوتر بر روی TFT LCD با آردوینو

#include <Adafruit_GFX.h>
#if defined(_GFXFONT_H_) //are we using the new library?
#include <Fonts/FreeSans9pt7b.h>
#define ADJ_BASELINE 11 //new fonts setCursor to bottom of letter
#else
#define ADJ_BASELINE 0 //legacy setCursor to top of letter
#endif
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GREY 0x7BEF
#include <stdio.h>
uint16_t ID;
uint8_t hh, mm, ss; //containers for current time
uint8_t conv2d(const char* p)
{
uint8_t v = 0;
if ('0' <= *p && *p <= '9') v = *p - '0';
return 10 * v + *++p - '0';
}
void setup(void)
{
Serial.begin(9600);
tft.reset();
ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
// if (ID == 0x00D3) ID = 0x9481; // write-only shield
if (ID == 0x00D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen(BLACK);
#if defined(_GFXFONT_H_)
tft.setFont(&FreeSans9pt7b);
#endif
hh = conv2d(__TIME__);
mm = conv2d(__TIME__ + 3);
ss = conv2d(__TIME__ + 6);
}
void loop(void)
{
int16_t x, y, dx, dy, idx;
uint16_t w, h, len, mask;
uint16_t colors[8] = { BLACK, WHITE, YELLOW, CYAN, GREEN, MAGENTA, RED, BLUE };
uint16_t height, width;
width = tft.width();
height = tft.height();
tft.fillRect(0, 0, 7, 3, WHITE);
tft.fillRect(313, 0, 7, 3, WHITE);
tft.fillRect(0, 237, 7, 3, WHITE);
tft.fillRect(313, 237, 7, 3, WHITE);
for (y = 0, w = 18, h = 3; y < 240; y += 13 * w + h) {
for (x = 25; x < 320 - 18; x += 2 * w) {
tft.fillRect(x, y, w, h, WHITE);
}
}
for (x = 0, w = 7, h = 18; x < 320; x += 17 * h + w) {
for (y = 21; y < 240 - 18; y += 2 * h) {
tft.fillRect(x, y, w, h, WHITE);
}
}
tft.fillRect(7, 3, 17 * 18, 13 * 18, GREY);
for (x = 7, y = 0, w = 1, h = 240; x < 320; x += 18) {
tft.fillRect(x, y, w, h, WHITE);
}
for (x = 0, y = 3, w = 320, h = 1; y < 240; y += 18) {
tft.fillRect(x, y, w, h, WHITE);
}
tft.fillRect(26, 22, 17, 99, tft.color565(0, 128, 64)); //turq
tft.fillRect(26, 120, 17, 99, tft.color565(255, 128, 192)); //pink
tft.fillRect(44, 22, 17, 35, tft.color565(0, 128, 255)); //blue
tft.fillRect(44, 184, 17, 35, tft.color565(255, 128, 64)); //orng
tft.fillRect(260, 22, 17, 35, tft.color565(0, 128, 255)); //blue
tft.fillRect(260, 184, 17, 35, tft.color565(255, 128, 64)); //orng
tft.fillRect(278, 22, 17, 99, tft.color565(128, 128, 0)); //grn
tft.fillRect(278, 120, 17, 99, tft.color565(128, 0, 255)); //purp
for (dx = 111; dx > -111; dx--) {
w = sqrt(111 * 111 - dx * dx);
y = 120 - dx;
dy = (y - 3) / 18;
mask = 7;
switch (dy) {
case 0:
case 1: idx = 1; len = 0; break;
case 2: idx = 0; len = 0; break;
case 3: idx = 0; len = 13; mask = 1; break;
case 4:
case 5: idx = 2; len = 38; break;
case 6:
case 7:
case 8: idx = 0; len = 0; break;
case 9: for (idx = 2; idx < 8; idx++) {
dy = 0xFF >> (7 - idx);
colors[idx] = tft.color565(dy, dy, dy);
}
idx = 2; len = 38; break;
case 10: idx = 1; len = 0; break;
case 11:
case 12: colors[2] = YELLOW; idx = 2; len = 0; break;
}
if (len == 0)
tft.fillRect(160 - w, y, w * 2, 1, colors[idx]);
else {
if (mask == 1) idx = 1 + (w) / len;
dy = w % len;
for (x = 160 - w; x < 160 + w; idx++) {
tft.fillRect(x, y, dy, 1, colors[idx & mask]);
x += dy;
if (x + len > 160 + w) dy = w % len;
else dy = len;
}
}
}
for (x = 72, y = 129, dx = 5, dy = 0; dx > 0; x += 2 * dx) {
tft.fillRect(x, y, dx, 36, WHITE);
dy += dx * 2;
if (dy >= 36) {
dy = 0;
dx--;
}
}
tft.fillRect(160 - 8, 5 * 18 + 3, 17, 3 * 18, BLACK);
for (x = 3 * 18 + 7, y = 6 * 18 + 3, w = 1, h = 18; x < 160 + 108; x += 18) {
tft.fillRect(x, y, w, h, WHITE);
}
tft.fillRect(160 - 108, 120, 108 * 2, 1, WHITE);
tft.fillRect(160, 5 * 18 + 3, 1, 3 * 18, WHITE);
tft.fillRect(108, 2 * 18 + 3, 6 * 18, 18, WHITE);
// tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
tft.fillRect(160 - 8, 11 * 18 + 3, 17, 31, RED);
tft.setCursor(160 - 36, 24 + ADJ_BASELINE);
tft.setTextColor(BLACK);
tft.setTextSize(1);
tft.print("320x240");
tft.setCursor(109, 43 + ADJ_BASELINE);
tft.setTextColor(BLACK);
tft.setTextSize(1);
tft.print("ID=0x");
tft.print(tft.readID(), HEX);
tft.setTextColor(WHITE, BLACK);
// tft.setFont(NULL);
// tft.setTextSize(2);
while (1) {
if (++ss > 59) {
ss = 0;
mm++;
if (mm > 59) {
mm = 0;
hh++;
if (hh > 23) hh = 0;
}
}
char buf[20];
sprintf(buf, "%02d:%02d:%02d", hh, mm, ss);
tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
tft.setCursor(128, 187 + ADJ_BASELINE);
tft.print(buf);
delay(1000);
}
}
 
 
 

اگر این نوشته‌ برایتان مفید بود لطفا کامنت بنویسید.

مطلب پیشنهادی:  با فوت کردن LED را خاموش و روشن کنید!

مطالعه دیگر جلسات این آموزش<< جلسه قبلی                    جلسه بعدی >>

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

10 دیدگاه

  1. سلام دوست عزیز خسته نباشید. ببخشید من هر کدوم از این کد ها رو توی نرم افزار آردوینو کپی می کنم نرم افزار ارور می گیره!!!

    لطفا راهنمایی کنید. تشکر

  2. اکبر سمندریان

    سلام وخسته نباشید
    ضمن سپاس از شما؛ پس از ساعتها جستجو بالاخره توسط سایت شما تونستم راه حل نصب ال سی دی خودم را پیدا کنم.
    یک نکته در پروزه دوم _ رسم اشکال هندسی _ به نظر درآخر متن پروژ کد نویسی بسته نشده است . اگر اینچنین است لطفا کد نویسی را تکمیل کنید .

  3. alisanjari

    سلم این ارور رو به من میده

    Arduino: 1.8.1 (Windows 7), Board: “Arduino/Genuino Uno”

    fatal error: Adafruit_GFX.h: No such file or directory

    #include

    ^

    compilation terminated.

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

  4. alisanjari

    #include “Adafruit_GFX.h”// Hardware-specific library

    ^

    compilation terminated.

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

  5. سلام رمز فایلا چیه؟

  6. ببخشید چگونه باید انیمیشن را نشان دهیم من از پروژه اول استفاده کردم

  7. سلام
    خیلی ممنون از آموزش خوبتون