به نام خدا : تو این مطلب از سری مطال پروژه آردوینو ، انشاالله قراره به آموزش نمایشگر رنگی با آردوینو بپردازیم، نمایشگر ما هسته مرکزیش ii9340 هستش و 2.4 اینچ هستش(320×240) و یه صفحه نمایش رنگی هستش که صفحه تاچ هم داره(البته اکثر این نمایشگرهایی که من دیدم صفحه تاچ هم داشتن حالا ممکنه بعضی نداشته باشن و وجود صفحه تاچ الزامی نیستش) این برد هایی که من دیدم و من خودم دارم یه رم ریدر هم دارن که میتونید ازش استفاده کنید برای نمایش اطلاعاتی که نمیشه تو میکرو قرارش داد مثل عکس(مثلا من 4-5 میگ عکس ریختم تو رم و تو نمایشگر نشون میدم، پروژش رو در ته مطلب قرار میدم)، خب معلومه این همه دیتا رو نمیشه تو میکرو ریخت لذا اینجا میتونه مفید باشه، البته موضوعی که هستش اینه که ما چرا از این نمایشگرها استفاده میکنیم؟ موضوعی که خیلی ها بهش توجه نمیکنن و فقط میگن این نمایشگر بدرد این میکرو نمیخوره چون سرعت این میکرو پایینه و از این جور حرفا، در حالی که فک میکنن فقط باید تو این نمایشگر فیلم(هندی!) نشون بدن و کاربرد صفحه نمایش رنگی فقط فقط همینه، لذا چون میخوایم فیلم نشون بدیم لذا! میکرو های فرکانس پایین جواب کار ما رو نمیدن لذا!!! باس بریم سمت میکرو های فرکانس بالا، از این جور حرفا من کم نشنیدم، در حالی که ما از نمایشگربرای مانیتورینگ پروژه هامون استفاده میکنیم و در قسمتی از صفحه نمایش قراره دیتا نشون بدیم و نه کل صفحه نمایش و نه شونصد تا عکس گنده!!! >>> خب بگذریم از بحث خارج شدیم(هنوز بحث نمایشگر رو شروع نکردم که بخوام ازش خارج بشم یا نشم ) >>> خب شوخلوق بسته بریم سر اصل مطلب >>> پروژه و آموزش راه اندازی lcd tft 2.4 inch با آردوینو
پروژه و آموزش راه اندازی lcd tft 2.4 inch با آردوینو
 
  خرید نمایشگر لمسی 2.4 اینچ آردوینو UNO و Mega2560
این نمایشگر رو میتونید از لینک زیر خرید کنید : خرید نمایشگر لمسی آردوینو

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

این شیلد نمایشگر رنگی 2.4 اینچ علاوه بر داشتن رم ریدر، یه صفحه تاچ هم داره که در بالا مشاهده میکنید.
اندازه این شیلد رو هم در زیر مشاهده میکنید :

  توضیح توابع کتابخانه lcd tft 2.4 inch با آردوینو
توجه مهم : اگه نمیخواید از رم استفاده کنید(مثلا نمیخواین عکسی چیزی نشون بدید و این عکس رو از رم بخونید) بهتره که کتابخونه های SPI و SD رو در پروژتون استفاده نکنید تا الکی حافظه میکرو اشغال نشه.
 
  کتابخانه و ساخت شی از کلاس کتابخانه   1 2 3 4 #include #include //(int CS=A3, int RS=A2, int WR=A1, int RD=A0, int RST=A4) MCUFRIEND_kbv tft(A3,A2,A1,A0,A4); خطوط اول دوم کتابخونه نمایشگر ما هستن که باس در اول پروژه قرارشون بدی و خط 4 هم یه شی از کلاس موجود در کتابخونه نمایشگر ساختیم، اگه نفهمیدید زیاد مهم نیست فقط این کد خط 4 رو بعد از قرار خطوط 1و2 قرارش بدید، ولی اگه میخواین بدونید برید بحث شی گرایی و کلاس و ساخت شیئ از کلاس، استفاده از توابع کلاس در برنامه های دیگه و… و عناوین مشابه رو تو نت بسرچید مطلب دربارش میاد و بعد بخونیدش.
خب تو خط 4 ما پایه های RS-WR-CS-RD-RST رو تعیین میکنیم که به کدوم پایه ها وصل هستن، اگه خواستید میتونید تغییرد بدید و اگه دوست نداشتید پایه ها رو تغییر بدید باید خط 4 رو به صورت زیر بنویسید(پایه ها رو تغییر بدید و در عمل درست نبندید نمایشگر چیزی نشون نمیده ها…)   1 MCUFRIEND_kbv tft;
  راه اندازی نمایشگر   1 2 uint16_t readID(void) voidbegin(uint16_t ID) خب برای راه اندازی نمایشگر بعد از فراخونی کتابخونه باید از تابع readID استفاده کنید که یه متغیر صحیح 16 بایتی به شما میده و بعد شما باید این متغییر 16 بایتی رو به تابع begin بدید تا نمایشگر آماده نمایش دیتا بشه.
  رسم انواع 4 ضلعی   1 2 3 4 fillRect(int16_tx,int16_ty,int16_tw,int16_th,uint16_t color) drawRect(int16_tx,int16_ty,int16_tw,int16_th,uint16_t color) fillRoundRect(int16_tx,int16_ty,int16_tw,int16_th,uint8_tR,uint16_t color) drawRoundRect(int16_tx,int16_ty,int16_tw,int16_th,uint8_tR,uint16_t color) fillRect : رسم یه 4ظلعی توپر
drawRect : رسم یه 4ظلعی تو خالی
FillRoundRect : رسم یه 4ظلعی توپر با گوشه های گرد
DrawRoundRect : رسم یه 4 ظلعی توخالی با گوشه های گرد X,Y : مختصات نقطه سمت چپ بالای 4 ظلعی
W,H : طول عرض 4ظلعی
COLOR : رنگ داخل 4ظلعی(برای 4 ظلعی تو پر “و”  توپر با گوشه های گرد)، رنگ دور 4ظلعی(برای 4ظلعی تو خالی “و”  4 ظلعی تو خالی با گوشه های گرد)
R : مقدار گردی گوشه های 4 ظلعی
  دایره تو خالی و دایره توپر   1 2 drawCircle(int16_t x0,int16_t y0,int16_tr,uint16_t color) fillCircle(int16_t x0,int16_t y0,int16_tr,uint16_t color) DrawCircle : رسم دایره تو خالی
FillCircle : رسم دایره تو پر
x0, y0 : مختصات مرکز دایره
Radius : شعاع دایره
COLOR : برای DrawCircle میشه رنگ دور دایره و برای FillCircle میشه رنگ داخل دایره
  مثلث تو خالی و تو پر   1 2 drawTriangle(int16_t x0,int16_t y0,int16_t x1,int16_t y1,int16_t x2,int16_t y2,uint16_t color) fillTriangle(int16_t x0,int16_t y0,int16_t x1,int16_t y1,int16_t x2,int16_t y2,uint16_t color) drawTriangle : رسم مثلث تو خالی
fillTriangle : رسم مثلث تو پر
x0, y0 : راس اول مثلث
x1, y1 : راس دوم مثلث
X2, y2 : راس سوم مثلث
COLOR : برای drawTriangle میشه رنگ دور مثلث و برای fillTriangle  میشه رنگ داخل مثلث
  رسم انواع خط   1 2 3 drawFastVLine(int16_tx,int16_ty,int16_th,uint16_t color) drawFastHLine(int16_tx,int16_ty,int16_tw,uint16_t color) drawLine(int16_t x0,int16_t y0,int16_t x1,int16_t y1,uint16_t color) رسم انواع خط
drawFastVLine : رسم خط عمودی، x,y مختصات نقطه شروع این خط هستن و h  اندازه این خط هستش، color هم رنگ خط هستش.(رسم خط با داشتن مختصات راس اول و اندازه خط)
drawFastHLine : رسم خط افقی، پارامترهاش مثل تابع بالا هستش. (رسم خط با داشتن مختصات راس اول و اندازه خط)
drawLine : رسم خط با داشتن مختصات دو سر خط، x0,y0 مختصات راس اول خط و x1,y1 مختصات راس دوم خط هستش و color هم رنگ خط هستش.
  چرخش صفحه نمایش   1 setRotation(uint8_tr) چرخش صفحه نمایش
0 : نمایش اطلاعات از بالا به پایین
1 : از راست به چپ
2 : از پایین به بالا
3 : از چپ به راست
توجه : تو موبایل های هوشمند اگه دیده باشید که صفحه موبایل رو میچرخونید و دیتاهای نمایش داده شده تو LCD هم میچرخه، این کار به کمک این تابع انجام میشه.
  خوندن وضعیت صفحه نمایش(تابع بالا برا اعمال کردن هستش و این برا خوندن)   1 uint8_t getRotation(void) به کمک این تابع هم میتونیم بفهمیم الان نمایش گر در کدوم وقع نمایشی هستش(تابع بالا رو ببنید این تابع رو متوجه میشید)، مقادیری که این تابع بر میگردونه در تابع بالا(setRotation) ذکر شده.
  معکوس کردن رنگهای صفحه نمایش   1 invertDisplay(booleani) معکوس کردن رنگهای صفحه نمایش
i : اگه true قرار بدید هر چیزی که تو صفحه نمایش هستش و یا خواهد بود رنگش معکوس میشه؛ و اگه false قرار بدید رنگ ها به صورت عادی نمایش داده میشن و معکوس نمیشن.
  تغییر رنگ صفحه نمایش   1 fillScreen(uint16_t color) تغییر رنگ صفحه نمایش
Color : رنگ مد نظرتون رو در اینجا قرار میدید، که باید به صورت یه متغییر صحیح 16 بایتی بهش دیتا بدین و یا کدهای زیر رو در اول پروژتون قرار بدید و از اون اسم ها(black, red , blue و…) برای نمایش رنگ استفاده کنید.(بهترین کار همینه)   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #define BLACK 0x0000 #define NAVY 0x000F #define DARKGREEN 0x03E0 #define DARKCYAN 0x03EF #define MAROON 0x7800 #define PURPLE 0x780F #define OLIVE 0x7BE0 #define LIGHTGREY 0xC618 #define DARKGREY 0x7BEF #define BLUE 0x001F #define GREEN 0x07E0 #define CYAN 0x07FF #define RED 0xF800 #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define ORANGE 0xFD20 #define GREENYELLOW 0xAFE5 #define PINK 0xF81F
  تغییر مختصات مکان نما   1 setCursor(int16_tx,int16_ty) تنظیم موقعیت مکان نما، مثلا برای نمایش متن در یه موقعیت خاص از صفحه نمایش ابتدا باید به کمک این تابع مکان نما رو به محل مد نظر برده و بعد متن رو نمایش میدیم.
x,y : مختصات مکان نما
  تغییر رنگ متن   1 2 setTextColor(uint16_tc) setTextColor(uint16_tc,uint16_tb) تغییر رنگ متن و پس زمینه متن، برای این کار اول باید رنگ متن رو تغییر بدید(یعنی از این توابع استفاده کنید) و بعد متنتون رو نمایش بدید(که یه چیز واضح هستش^_^)
تابع اولی فقط رنگ متن رو تغییر میده.
تابع دومی علاوه بر تغییر رنگ متن، رنگ پس زمینه رو هم تغییر میده.
c : رنگ متن مد نظرتون
b : رنگ پس زمینه
  تغییر اندازه متن   1 setTextSize(uint8_ts) برای تعیین اندازه متنتون باید از این تابع استفاده کنید، که به جای S باید عددی بین 1 تا تقریبا 5 قرار بدید، البته از این تابع اول استفاده میکنید و بعد متنتون رو نمایش میدید، متنی که نمایش داده میشه در اندازه مد نظر شما خواهد بود!!!
  نماش یه رشته در صفحه نمایش   1 2 tft.println("DMF313.IR"); tft.print("DMF313.IR"); این دو تابع برای نمایش یه متن در نمایشگر هستن، تابع اولی بعد از نمایش دادن متن، موقعیت مکان نما رو به خط بعدی میبره ولی تابع دومی فقط متن رو نشون میده، به جای آدرس سایت ما میتونید متنتون رو قرار بدید، در ضمن اگه بخواین متنتون رو در جای خاصی از صفحه نمایش نمایش بدید باید از تابع setCursor اول استفاده کنید و بعد متنتون رو نمایش بدید.
  نمایش یه کاراکتر در صفحه نمایش   1 write(uint8_tc) برای نمایش کاراکتر از این تابع استفاده میکنند.که کد اسکی بهش میدی برات کاراکترش رو نمایش میده و یا خود کاراکتر رو میدی و برات نمایش میده، فقط و فقط یه کاراکتر رو میتونید نمایش بدید به کم این تابع در هر با استفاده ازش.
  نمایش یه کاراکتر در صفحه نمایش+امکانات ویژه!   1 drawChar(int16_tx,int16_ty,unsignedcharc,uint16_t color,uint16_t bg,uint8_t size) نمایش یه کاراکتر، این تابع مثل تابع بالا هستش ولی یه سری امکانات دیگه هم داره، از جمله تعیین مکان نمایش کاراکتر، اندازه، رنگ کاراکتر و پس زمینه کاراکتر رو میتونید تعیین کنید.
Size : اندازه کاراکتر
Color : رنگ کاراکتر
Bg : رنگ پس زمینه کاراکتر
C : کاراکتری که قراره نمایش داده بشه
X,y : مختصاتی که کاراکتر باید نمایش داده بشه.
  طول و عرض صفحه نمایش   1 2 int16_t width(void) int16_t height(void) این دو تابع مقدار طول عرض نمایشگر تون رو بهتون نمایش میده.
  دادن رنگ مد نظرتون بر حسب RGB و گرفتن رنگ نهای مد نظر   1 uint16_t color565(uint8_tr,uint8_tg,uint8_tb) خب این تابع کارش اینه که شما رنگ بر حسب RGB بهش میدید، یعنی مقدار 3 رنگ رو بهش میدید و ترکیب این 3 رنگ رو متغییرش رو به ما میده، اگه بخواین یکم خلاقیت در پروژتون به خرج بدید این تابع میتونه مفید باشه،
در مطلب زیر یه نرم  افزار هستش که به درد این تابع میخوره، بهترین نرم افزار هستش در این زمینه، کارش اینه که رنگ مد نظرتون رو انتخاب میکنید و کد RGB ایش رو به شما میده.
پروژه و آموزش راه اندازی lcd tft 1.8 inch با آردوینو
  نمایش یه پیکسل(نقطه) در صفحه نمایش + خوندن رنگ یه نقطعه از صفحه نمایش   1 2 drawPixel(int16_tx,int16_ty,uint16_t color) uint16_t readPixel(int16_tx,int16_ty) drawPixel : نمایش یه پیکسل رنگی در مختصات x,y با رنگ color
readPixel : خوندن رنگ پیکسل موجود در مختصات x,y
  توابعی که توضیح ندادمش   1 2 voidsetTextWrap(booleanw) vertScroll(int16_t top,int16_t scrollines,int16_t offset) setTextWrap : این تابع رو متوجه عملکردش نشدم من، اگه کسی میدونه بگه.
vertScroll : اینو متوجه شدم ولی حال و وقتش رو ندارم.
  نمایش عکس در نمایشگر   1 ShowBMP24BIT(char*filename,intx,inty) عرضم به حظورتون که این تابع همون طور که از اسمش معلومه برای نمایش عکس های 24بیتی از نوع bmp هستش، لذا نمیتونید عکسهایی با فرمت png – gif – bmp32bit – bmp16bit – jpg و… رو به کمک این تابع نشون بدید، چون نوع دیکود شدن این عکس ها فرق داره با هم و باید متناسب با هر کدوم یه تابع نوشت، این تابع فقط برای عکس هایی با فرمت bmp و اونم 24بیتی جواب میده فقط، برای عکسهایی با فرمت دیگه باید خودتون دست بکار بشید و تابعش رو بنویسید.(عمرا کسی بره همچین کاری کنه )
حالا تصاویری که شما دارید اول باید اندازش رو به محدوده اندازه نمایشگر ببرید و بعد فرمتش رو تغییر بدید که هر دو کار رو میتونید در نرم افزار paint ویندوز و یا فوتوشاپ انجام بدید و چون اینجا جاش نیست توضیح بدم لذا نمیدم.(کسی مشکلی داره؟ )
البته این تابع به این صورته که اسم عکس رو بهش میدی و میره این عکس رو از رم میخورنه، در کل این تابع برای نمایش عکس از روی رم هستش.
filename : آدرس فایل و یا نام فایل(اگه در root باشه عکس شما دیگه آدرس نمیخواد و همون نام عکس رو بفرستید)
x,y : مکان شروع نمایش عکس
 
برای این کار(نمایش عکس) چون از رم استفاده میکنیم برای نمایش عکس(عکسهامون رو میریزیم تو رم و از رم عکس ها رو میخونیم) بایت ابتدا کتابخونه های مربوط به برقراری ارتباط با رم رو قرار بدید در پروژه تون :   1 2 3 #include #include #define SD_CS 10
و بعد اگه میخواین عکس نمایش بدین و این عکس رو از رم بخونید باید توابع زیر رو در پروژه قرار بدید و از تابع ShowBMP24BIT برای نمایش عکس طبق توضیحات بالا استفاده کنید.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 voidShowBMP24BIT(char*filename,intx,inty){   File bmpFile; intbmpWidth,bmpHeight;// W+H in pixels uint8_t bmpDepth;// Bit depth (currently must be 24) uint32_t bmpImageoffset;// Start of image data in file uint32_t rowSize;// Not always = bmpWidth; may have padding uint8_t sdbuffer[60];// pixel in buffer (R+G+B per pixel) uint16_t lcdbuffer[20];// pixel out buffer (16-bit per pixel) uint8_t buffidx=sizeof(sdbuffer);// Current position in sdbuffer booleangoodBmp=false;// Set to true on valid header parse booleanflip=true;// BMP is stored bottom-to-top intw,h,row,col; uint8_tr,g,b; uint32_t pos=0,startTime=millis(); uint8_t lcdidx=0; booleanfirst=true; uint32_t DataShow;   if((x>=tft.width())||(y>=tft.height()))return;   //Serial.println(); //Serial.print(F("Loading image '")); //Serial.print(filename); //Serial.println('\'');   // Open requested file on SD card if((bmpFile=SD.open(filename))==NULL){ //Serial.println(F("File not found")); return; }   // Parse BMP header if(read16(bmpFile)==0x4D42){// BMP signature DataShow=read32(bmpFile); //Serial.println(F("File size: ")); Serial.println(DataShow); (void)read32(bmpFile);// Read & ignore creator bytes bmpImageoffset=read32(bmpFile);// Start of image data //Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC); // Read DIB header DataShow=read32(bmpFile); //Serial.print(F("Header size: ")); Serial.println(DataShow); bmpWidth=read32(bmpFile); bmpHeight=read32(bmpFile); if(read16(bmpFile)==1){// # planes -- must be '1' bmpDepth=read16(bmpFile);// bits per pixel //Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth); if((bmpDepth==24)&&(read32(bmpFile)==0)){// 0 = uncompressed   goodBmp=true;// Supported BMP format -- proceed! //Serial.print(F("Image size: ")); //Serial.print(bmpWidth); //Serial.print('x'); //Serial.println(bmpHeight);   // BMP rows are padded (if needed) to 4-byte boundary rowSize=(bmpWidth*3+3)&~3;   // If bmpHeight is negative, image is in top-down order. // This is not canon but has been observed in the wild. if(bmpHeight0){ bmpHeight=-bmpHeight; flip=false; }   // Crop area to be loaded w=bmpWidth; h=bmpHeight; if((x+w-1)>=tft.width())w=tft.width()-x; if((y+h-1)>=tft.height())h=tft.height()-y;   // Set TFT address window to clipped image bounds tft.setAddrWindow(x,y,x+w-1,y+h-1);   for(row=0;rowh;row++){// For each scanline... // Seek to start of scan line. It might seem labor- // intensive to be doing this on every line, but this // method covers a lot of gritty details like cropping // and scanline padding. Also, the seek only takes // place if the file position actually needs to change // (avoids a lot of cluster math in SD library). if(flip)// Bitmap is stored bottom-to-top order (normal BMP) pos=bmpImageoffset+(bmpHeight-1-row)*rowSize; else// Bitmap is stored top-to-bottom pos=bmpImageoffset+row*rowSize; if(bmpFile.position()!=pos){// Need seek? bmpFile.seek(pos); buffidx=sizeof(sdbuffer);// Force buffer reload }   for(col=0;colw;col++){// For each column... // Time to read more pixel data? if(buffidx>=sizeof(sdbuffer)){// Indeed // Push LCD buffer to the display first if(lcdidx>0){ tft.pushColors(lcdbuffer,lcdidx,first); lcdidx=0; first=false; } bmpFile.read(sdbuffer,sizeof(sdbuffer)); buffidx=0;// Set index to beginning }   // Convert pixel from BMP to TFT format b=sdbuffer[buffidx++]; g=sdbuffer[buffidx++]; r=sdbuffer[buffidx++]; lcdbuffer[lcdidx++]=tft.color565(r,g,b); }// end pixel }// end scanline     // Write any remaining data to LCD if(lcdidx>0){ tft.pushColors(lcdbuffer,lcdidx,first); } //Serial.print(F("Loaded in ")); //Serial.print(millis() - startTime); //Serial.println(" ms"); }// end goodBmp } }     bmpFile.close(); //if (!goodBmp) Serial.println(F("BMP format not recognized.")); } uint16_t read16(Filef){ uint16_t result; ((uint8_t*)&result)[0]=f.read();// LSB ((uint8_t*)&result)[1]=f.read();// MSB returnresult; } uint32_t read32(Filef){ uint32_t result; ((uint8_t*)&result)[0]=f.read();// LSB ((uint8_t*)&result)[1]=f.read(); ((uint8_t*)&result)[2]=f.read(); ((uint8_t*)&result)[3]=f.read();// MSB returnresult; }
  پروژه نمایشگر لمسی و رنگی 2.4 اینچ با آردوینو
خب در زیر چند تا پروژه براتون قرار میدم، در اول هر کدوم توضیحی در بارش میدم.
  1) پروژه تست تمام توابع lcd tft آردوینو
این پروژه برا تست تمام توابع این کتابخونه هستش (غیر از تابع نمایش عکس) که میتونید با نگاه کردن بهش همه چیز رو یاد بگیرید.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 #include #include //(int CS=A3, int RS=A2, int WR=A1, int RD=A0, int RST=A4) MCUFRIEND_kbv tft(A3,A2,A1,A0,A4);     #define BLACK 0x0000 #define NAVY 0x000F #define DARKGREEN 0x03E0 #define DARKCYAN 0x03EF #define MAROON 0x7800 #define PURPLE 0x780F #define OLIVE 0x7BE0 #define LIGHTGREY 0xC618 #define DARKGREY 0x7BEF #define BLUE 0x001F #define GREEN 0x07E0 #define CYAN 0x07FF #define RED 0xF800 #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define ORANGE 0xFD20 #define GREENYELLOW 0xAFE5 #define PINK 0xF81F     uint16_t ColorArray[19]={ BLACK,NAVY,DARKGREEN,DARKCYAN,MAROON,PURPLE,OLIVE,LIGHTGREY,DARKGREY, BLUE,GREEN,CYAN,RED,MAGENTA,YELLOW,WHITE,ORANGE,GREENYELLOW,PINK };       voidsetup(){   tft.reset();   uint16_t identifier=tft.readID(); tft.begin(0x9340);     tft.reset(); uint16_t Identifier=tft.readID(); if(Identifier==0xEFEF)Identifier=0x9341; tft.begin(Identifier); }   voidloop(){   FillScreen(1); delay(2000); SetRotation_With_FillScreen();// fillScreen + setRotation delay(2000); SetRotation_With_PrintData();// setCursor + setTextSize + println + fillScreen + setRotation delay(2000); InvertDisplay_With_PrintData(); delay(2000); FillRect_setTextColor(); delay(2000); DrawLine(); delay(2000); DrawFastHLine_DrawFastVLine(); delay(2000); DrawRect(); delay(2000); DrawRect(); delay(2000); DrawRoundRect(); delay(2000); FillCircle_DrawCircle(); delay(2000); DrawTriangle(); delay(2000); FillTriangle(); delay(2000); Print_Println(); delay(2000); Write_DrawChar(); delay(2000); DrawPixel_Noise(5000); }       voidFillScreen(intDelay){ tft.fillScreen(BLACK); delay(Delay); tft.fillScreen(NAVY); delay(Delay); tft.fillScreen(DARKGREEN); delay(Delay); tft.fillScreen(DARKCYAN); delay(Delay); tft.fillScreen(MAROON); delay(Delay); tft.fillScreen(PURPLE); delay(Delay); tft.fillScreen(OLIVE); delay(Delay); tft.fillScreen(LIGHTGREY); delay(Delay); tft.fillScreen(DARKGREY); delay(Delay); tft.fillScreen(BLUE); delay(Delay); tft.fillScreen(GREEN); delay(Delay); tft.fillScreen(CYAN); delay(Delay); tft.fillScreen(RED); delay(Delay); tft.fillScreen(MAGENTA); delay(Delay); tft.fillScreen(YELLOW); delay(Delay); tft.fillScreen(WHITE); delay(Delay); tft.fillScreen(ORANGE); delay(Delay); tft.fillScreen(GREENYELLOW); delay(Delay); tft.fillScreen(PINK); delay(Delay); }   voidSetRotation_With_FillScreen(){ tft.setRotation(0);// 0 Digre tft.fillScreen(BLACK); delay(1000); tft.setRotation(1);// 90 Digre tft.fillScreen(NAVY); delay(1000); tft.setRotation(2);// 180 Digre tft.fillScreen(DARKGREEN); delay(1000); tft.setRotation(3);// 270 Digre tft.fillScreen(MAROON); delay(1000); }   voidSetRotation_With_PrintData(){ tft.setTextSize(4);   tft.setCursor(0,0); tft.setRotation(0);// 0 Digre tft.fillScreen(BLACK); tft.println("DMF313.IR"); delay(1000);   tft.setCursor(0,0); tft.setRotation(1);// 90 Digre tft.fillScreen(BLACK); tft.println("DMF313.IR"); delay(1000);   tft.setCursor(0,0); tft.setRotation(2);// 180 Digre tft.fillScreen(BLACK); tft.println("DMF313.IR"); delay(1000);   tft.setCursor(0,0); tft.setRotation(3);// 270 Digre tft.fillScreen(BLACK); tft.println("DMF313.IR"); delay(1000); }   voidInvertDisplay_With_PrintData(){   tft.fillScreen(BLACK);   tft.setRotation(0);// 0 Digre tft.setTextSize(3); tft.setCursor(20,160); tft.println("INVERT Test");     for(inti=1;i3;i++){ tft.invertDisplay(true); delay(1000); tft.invertDisplay(false); delay(1000); } }   voidDrawLine(){ intx1,y1,x2,y2,w=tft.width(),h=tft.height();   tft.fillScreen(BLACK); x1=y1=0; y2=h-1; for(x2=0;x2w;x2+=6)tft.drawLine(x1,y1,x2,y2,RED); x2=w-1; for(y2=0;y2h;y2+=6)tft.drawLine(x1,y1,x2,y2,RED);   tft.fillScreen(BLACK); x1=w-1; y1=0; y2=h-1; for(x2=0;x2w;x2+=6)tft.drawLine(x1,y1,x2,y2,MAGENTA); x2=0; for(y2=0;y2h;y2+=6)tft.drawLine(x1,y1,x2,y2,MAGENTA);   tft.fillScreen(BLACK); x1=0; y1=h-1; y2=0; for(x2=0;x2w;x2+=6)tft.drawLine(x1,y1,x2,y2,GREEN); x2=w-1; for(y2=0;y2h;y2+=6)tft.drawLine(x1,y1,x2,y2,GREEN);   tft.fillScreen(BLACK); x1=w-1; y1=h-1; y2=0; for(x2=0;x2w;x2+=6)tft.drawLine(x1,y1,x2,y2,WHITE); x2=0; for(y2=0;y2h;y2+=6)tft.drawLine(x1,y1,x2,y2,WHITE); } voidDrawFastHLine_DrawFastVLine(){ intx,y,w=tft.width(),h=tft.height();   tft.fillScreen(BLACK); for(y=0;yh;y+=5)tft.drawFastHLine(0,y,w,BLUE); for(x=0;xw;x+=5)tft.drawFastVLine(x,0,h,GREEN); }   voidFillRect_setTextColor(){ // Resolution : 240 x 320 // 240/20=12, 320/20=16   // -------- line 1 ---------------- tft.fillRect(0,0,60,64,BLACK); tft.fillRect(60,0,60,64,NAVY); tft.fillRect(120,0,60,64,DARKGREEN); tft.fillRect(180,0,60,64,DARKCYAN); // -------- line 2 ---------------- tft.fillRect(0,64,60,64,MAROON); tft.fillRect(60,64,60,64,PURPLE); tft.fillRect(120,64,60,64,OLIVE); tft.fillRect(180,64,60,64,LIGHTGREY); // -------- line 3 ---------------- tft.fillRect(0,128,60,64,DARKGREY); tft.fillRect(60,128,60,64,BLUE); tft.fillRect(120,128,60,64,GREEN); tft.fillRect(180,128,60,64,CYAN); // -------- line 4 ---------------- tft.fillRect(0,192,60,64,RED); tft.fillRect(60,192,60,64,MAGENTA); tft.fillRect(120,192,60,64,YELLOW); tft.fillRect(180,192,60,64,WHITE); // -------- line 5 ---------------- tft.fillRect(0,256,60,64,ORANGE); tft.fillRect(60,256,60,64,GREENYELLOW); tft.fillRect(120,256,60,64,PINK); tft.fillRect(180,256,60,64,RED);   tft.setTextSize(3); tft.setTextColor(BLACK); tft.setCursor(5,160); tft.println("FillRect Test"); } voidDrawRect(){ // Resolution : 240 x 320 // 240/20=12, 320/20=16   tft.fillScreen(WHITE);   // -------- line 1 ---------------- tft.drawRect(0,0,60,64,BLACK); tft.drawRect(60,0,60,64,NAVY); tft.drawRect(120,0,60,64,DARKGREEN); tft.drawRect(180,0,60,64,DARKCYAN); // -------- line 2 ---------------- tft.drawRect(0,64,60,64,MAROON); tft.drawRect(60,64,60,64,PURPLE); tft.drawRect(120,64,60,64,OLIVE); tft.drawRect(180,64,60,64,LIGHTGREY); // -------- line 3 ---------------- tft.drawRect(0,128,60,64,DARKGREY); tft.drawRect(60,128,60,64,BLUE); tft.drawRect(120,128,60,64,GREEN); tft.drawRect(180,128,60,64,CYAN); // -------- line 4 ---------------- tft.drawRect(0,192,60,64,RED); tft.drawRect(60,192,60,64,MAGENTA); tft.drawRect(120,192,60,64,YELLOW); tft.drawRect(180,192,60,64,WHITE); // -------- line 5 ---------------- tft.drawRect(0,256,60,64,ORANGE); tft.drawRect(60,256,60,64,GREENYELLOW); tft.drawRect(120,256,60,64,PINK); tft.drawRect(180,256,60,64,RED);   tft.setTextSize(3); tft.setTextColor(BLACK); tft.setCursor(5,160); tft.println("DrawRect Test"); } voidFillRoundRect(){ // Resolution : 240 x 320 // 240/20=12, 320/20=16   tft.fillScreen(WHITE);   // -------- line 1 ---------------- tft.fillRoundRect(0,0,60,64,15,BLACK); tft.fillRoundRect(60,0,60,64,15,NAVY); tft.fillRoundRect(120,0,60,64,15,DARKGREEN); tft.fillRoundRect(180,0,60,64,15,DARKCYAN); // -------- line 2 ---------------- tft.fillRoundRect(0,64,60,64,15,MAROON); tft.fillRoundRect(60,64,60,64,15,PURPLE); tft.fillRoundRect(120,64,60,64,15,OLIVE); tft.fillRoundRect(180,64,60,64,15,LIGHTGREY); // -------- line 3 ---------------- tft.fillRoundRect(0,128,60,64,15,DARKGREY); tft.fillRoundRect(60,128,60,64,15,BLUE); tft.fillRoundRect(120,128,60,64,15,GREEN); tft.fillRoundRect(180,128,60,64,15,CYAN); // -------- line 4 ---------------- tft.fillRoundRect(0,192,60,64,15,RED); tft.fillRoundRect(60,192,60,64,15,MAGENTA); tft.fillRoundRect(120,192,60,64,15,YELLOW); tft.fillRoundRect(180,192,60,64,15,WHITE); // -------- line 5 ---------------- tft.fillRoundRect(0,256,60,64,15,ORANGE); tft.fillRoundRect(60,256,60,64,15,GREENYELLOW); tft.fillRoundRect(120,256,60,64,15,PINK); tft.fillRoundRect(180,256,60,64,15,RED);   tft.setTextSize(3); tft.setTextColor(BLACK); tft.setCursor(5,160); tft.println("FillRoundRect"); } voidDrawRoundRect(){ // Resolution : 240 x 320 // 240/20=12, 320/20=16   tft.fillScreen(WHITE);   // -------- line 1 ---------------- tft.drawRoundRect(0,0,60,64,15,BLACK); tft.drawRoundRect(60,0,60,64,15,NAVY); tft.drawRoundRect(120,0,60,64,15,DARKGREEN); tft.drawRoundRect(180,0,60,64,15,DARKCYAN); // -------- line 2 ---------------- tft.drawRoundRect(0,64,60,64,15,MAROON); tft.drawRoundRect(60,64,60,64,15,PURPLE); tft.drawRoundRect(120,64,60,64,15,OLIVE); tft.drawRoundRect(180,64,60,64,15,LIGHTGREY); // -------- line 3 ---------------- tft.drawRoundRect(0,128,60,64,15,DARKGREY); tft.drawRoundRect(60,128,60,64,15,BLUE); tft.drawRoundRect(120,128,60,64,15,GREEN); tft.drawRoundRect(180,128,60,64,15,CYAN); // -------- line 4 ---------------- tft.drawRoundRect(0,192,60,64,15,RED); tft.drawRoundRect(60,192,60,64,15,MAGENTA); tft.drawRoundRect(120,192,60,64,15,YELLOW); tft.drawRoundRect(180,192,60,64,15,WHITE); // -------- line 5 ---------------- tft.drawRoundRect(0,256,60,64,15,ORANGE); tft.drawRoundRect(60,256,60,64,15,GREENYELLOW); tft.drawRoundRect(120,256,60,64,15,PINK); tft.drawRoundRect(180,256,60,64,15,RED);   tft.setTextSize(3); tft.setTextColor(BLACK); tft.setCursor(5,160); tft.println("DrawRoundRect"); }   voidFillCircle_DrawCircle(){ tft.fillScreen(BLACK);   // -------- line 1 ---------------- tft.fillCircle(30,30,30,WHITE); tft.fillCircle(90,30,30,WHITE); tft.fillCircle(150,30,30,WHITE); tft.fillCircle(210,30,30,WHITE); // -------- line 2 ---------------- tft.fillCircle(30,90,30,WHITE); tft.fillCircle(90,90,30,WHITE); tft.fillCircle(150,90,30,WHITE); tft.fillCircle(210,90,30,WHITE); // -------- line 3 ---------------- tft.fillCircle(30,150,30,WHITE); tft.fillCircle(90,150,30,WHITE); tft.fillCircle(150,150,30,WHITE); tft.fillCircle(210,150,30,WHITE); // -------- line 4 ---------------- tft.fillCircle(30,210,30,WHITE); tft.fillCircle(90,210,30,WHITE); tft.fillCircle(150,210,30,WHITE); tft.fillCircle(210,210,30,WHITE); // -------- line 5 ---------------- tft.fillCircle(30,270,30,WHITE); tft.fillCircle(90,270,30,WHITE); tft.fillCircle(150,270,30,WHITE); tft.fillCircle(210,270,30,WHITE);     delay(1000);     // -------- line 1 ---------------- tft.drawCircle(30,30,20,RED); tft.drawCircle(90,30,20,RED); tft.drawCircle(150,30,20,RED); tft.drawCircle(210,30,20,RED); // -------- line 2 ---------------- tft.drawCircle(30,90,20,RED); tft.drawCircle(90,90,20,RED); tft.drawCircle(150,90,20,RED); tft.drawCircle(210,90,20,RED); // -------- line 3 ---------------- tft.drawCircle(30,150,20,RED); tft.drawCircle(90,150,20,RED); tft.drawCircle(150,150,20,RED); tft.drawCircle(210,150,20,RED); // -------- line 4 ---------------- tft.drawCircle(30,210,20,RED); tft.drawCircle(90,210,20,RED); tft.drawCircle(150,210,20,RED); tft.drawCircle(210,210,20,RED); // -------- line 5 ---------------- tft.drawCircle(30,270,20,RED); tft.drawCircle(90,270,20,RED); tft.drawCircle(150,270,20,RED); tft.drawCircle(210,270,20,RED); }   voidDrawTriangle(){ intn,i,cx=tft.width()/2-1,cy=tft.height()/2-1;   tft.fillScreen(BLACK); n=min(cx,cy);   for(i=0;in;i+=15){ tft.drawTriangle( cx,cy-i,// peak cx-i,cy+i,// bottom left cx+i,cy+i,// bottom right tft.color565(0,0,i)); } } voidFillTriangle(){ inti,cx=tft.width()/2-1,cy=tft.height()/2-1;   tft.fillScreen(BLACK);   for(i=min(cx,cy);i>10;i-=15) tft.fillTriangle(cx,cy-i,cx-i,cy+i,cx+i,cy+i,tft.color565(0,i,i)); }   voidPrint_Println(){ tft.fillScreen(BLACK);   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.print(" "); tft.setTextColor(GREEN,RED); tft.setTextSize(4); tft.println("IRAN");   tft.setTextColor(GREEN); tft.setTextSize(4); tft.println("DMF313.IR");   tft.setTextSize(2); tft.println("Mahdi Damarchilu!");   tft.setTextSize(1); tft.println("salam, mn 22 salame tagriban,"); tft.println("ham daneshjoo hastam va ham nistam!!!"); tft.println("be omid pishraft keshvaremon iran"); tft.println("be omin azadi gods az dast sagag"); tft.println("be omin nabodi al seood va vahabiat"); tft.println("be omid mordan dar rah khoda,"); tft.println("dar rah sarvarmoon, seyed va salar shahidan"); tft.println("Emam Hosein"); }   voidWrite_DrawChar(){ tft.fillScreen(BLACK); tft.setCursor(0,0); tft.setTextColor(WHITE); tft.setTextSize(3);   for(inti=1;i127;i++) if(i!=10) tft.write(i);   tft.drawChar(110,260,'A',WHITE,BLUE,5); }   voidDrawPixel_Noise(longintNumber){ tft.fillScreen(WHITE); intx,y,C;   for(inti=0;iNumber;i++){ x=random(0,239); y=random(0,319); C=random(0,19);   tft.drawPixel(x,y,ColorArray[C]); } }
 
فیلم عملکرد کدهای پروژه بالا رو در زیر میبینید، شرمنده اگه کیفیت پایین هستش، موبایلمون سادس و اینو هم با وبکم لبتاب گرفتم، اگه کسی موبایل داره از پروژه فیلم بگیره و بفرسته ممنون میشم
http://www.aparat.com/v/fDuba 2) پروژه نمایش تصویر در lcd tft آردوینو
تو این پروژه یه سری من عکس هم نشون میدم، فایل این عکس ها رو براتون در زیر قرار میدم و باس دانلودش کنید ودر رم بریزید و رم رو هم بزارید داخل رم ریدر و …(کلا آبو بریزید جایی که میسوزه، این دیگه معلومه و نیاز به گفتن نداره که )
توجه : اگه میخواین از رم استفاده کنید و عکس نشون بدید باید توابع read32 و read16 و ShowBMP24BIT رو در پروژتون قرار بدید و برای نمایش عکس از تابع ShowBMP24BIT استفاده کنید.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 #include #include #define SD_CS 10   #include #include //(int CS=A3, int RS=A2, int WR=A1, int RD=A0, int RST=A4) MCUFRIEND_kbv tft(A3,A2,A1,A0,A4);         #define BLACK 0x0000 #define NAVY 0x000F #define DARKGREEN 0x03E0 #define DARKCYAN 0x03EF #define MAROON 0x7800 #define PURPLE 0x780F #define OLIVE 0x7BE0 #define LIGHTGREY 0xC618 #define DARKGREY 0x7BEF #define BLUE 0x001F #define GREEN 0x07E0 #define CYAN 0x07FF #define RED 0xF800 #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define ORANGE 0xFD20 #define GREENYELLOW 0xAFE5 #define PINK 0xF81F       voidsetup(){ tft.reset();   uint16_t identifier=tft.readID(); tft.begin(0x9340);   if(!SD.begin(SD_CS)){ return; }     tft.reset(); uint16_t Identifier=tft.readID(); if(Identifier==0xEFEF)Identifier=0x9341; tft.begin(Identifier); }   voidloop(){ Tabligat(); ShowImage(); }       voidTabligat(){// ^_^ tft.setRotation(0);   // آواتار من + یکم بازی با رنگ و معکوس کردن رنگ ها ShowBMP24BIT("DMF313.bmp",0,0); for(inti=1;i5;i++){ tft.invertDisplay(true); delay(1000); tft.invertDisplay(false); delay(1000); } }   voidShowImage(){ tft.setRotation(0);   ShowBMP24BIT("1.bmp",0,0);// delay(1000); ShowBMP24BIT("2.bmp",0,0);// delay(1000); ShowBMP24BIT("3.bmp",0,0);// delay(1000); ShowBMP24BIT("4.bmp",0,0);// delay(1000); ShowBMP24BIT("5.bmp",0,0);// delay(1000); ShowBMP24BIT("6.bmp",0,0);// delay(1000); ShowBMP24BIT("7.bmp",0,0);// delay(1000); ShowBMP24BIT("8.bmp",0,0);// delay(1000); ShowBMP24BIT("9.bmp",0,0);// delay(1000); ShowBMP24BIT("10.bmp",0,0);// delay(1000); ShowBMP24BIT("11.bmp",0,0);// delay(1000); ShowBMP24BIT("12.bmp",0,0);// delay(1000); ShowBMP24BIT("13.bmp",0,0);// delay(1000); ShowBMP24BIT("14.bmp",0,0);// delay(1000); ShowBMP24BIT("15.bmp",0,0);// delay(1000); ShowBMP24BIT("16.bmp",0,0);//delay(1000);     tft.setRotation(1); ShowBMP24BIT("17.bmp",0,0);//delay(1000); ShowBMP24BIT("18.bmp",0,0);//delay(1000); ShowBMP24BIT("19.bmp",0,0);//delay(1000); ShowBMP24BIT("20.bmp",0,0);//delay(1000); ShowBMP24BIT("21.bmp",0,0);//delay(1000); }           voidShowBMP24BIT(char*filename,intx,inty){   File bmpFile; intbmpWidth,bmpHeight;// W+H in pixels uint8_t bmpDepth;// Bit depth (currently must be 24) uint32_t bmpImageoffset;// Start of image data in file uint32_t rowSize;// Not always = bmpWidth; may have padding uint8_t sdbuffer[60];// pixel in buffer (R+G+B per pixel) uint16_t lcdbuffer[20];// pixel out buffer (16-bit per pixel) uint8_t buffidx=sizeof(sdbuffer);// Current position in sdbuffer booleangoodBmp=false;// Set to true on valid header parse booleanflip=true;// BMP is stored bottom-to-top intw,h,row,col; uint8_tr,g,b; uint32_t pos=0,startTime=millis(); uint8_t lcdidx=0; booleanfirst=true; uint32_t DataShow;   if((x>=tft.width())||(y>=tft.height()))return;   //Serial.println(); //Serial.print(F("Loading image '")); //Serial.print(filename); //Serial.println('\'');   // Open requested file on SD card if((bmpFile=SD.open(filename))==NULL){ //Serial.println(F("File not found")); return; }   // Parse BMP header if(read16(bmpFile)==0x4D42){// BMP signature DataShow=read32(bmpFile); //Serial.println(F("File size: ")); Serial.println(DataShow); (void)read32(bmpFile);// Read & ignore creator bytes bmpImageoffset=read32(bmpFile);// Start of image data //Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC); // Read DIB header DataShow=read32(bmpFile); //Serial.print(F("Header size: ")); Serial.println(DataShow); bmpWidth=read32(bmpFile); bmpHeight=read32(bmpFile); if(read16(bmpFile)==1){// # planes -- must be '1' bmpDepth=read16(bmpFile);// bits per pixel //Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth); if((bmpDepth==24)&&(read32(bmpFile)==0)){// 0 = uncompressed   goodBmp=true;// Supported BMP format -- proceed! //Serial.print(F("Image size: ")); //Serial.print(bmpWidth); //Serial.print('x'); //Serial.println(bmpHeight);   // BMP rows are padded (if needed) to 4-byte boundary rowSize=(bmpWidth*3+3)&~3;   // If bmpHeight is negative, image is in top-down order. // This is not canon but has been observed in the wild. if(bmpHeight0){ bmpHeight=-bmpHeight; flip=false; }   // Crop area to be loaded w=bmpWidth; h=bmpHeight; if((x+w-1)>=tft.width())w=tft.width()-x; if((y+h-1)>=tft.height())h=tft.height()-y;   // Set TFT address window to clipped image bounds tft.setAddrWindow(x,y,x+w-1,y+h-1);   for(row=0;rowh;row++){// For each scanline... // Seek to start of scan line. It might seem labor- // intensive to be doing this on every line, but this // method covers a lot of gritty details like cropping // and scanline padding. Also, the seek only takes // place if the file position actually needs to change // (avoids a lot of cluster math in SD library). if(flip)// Bitmap is stored bottom-to-top order (normal BMP) pos=bmpImageoffset+(bmpHeight-1-row)*rowSize; else// Bitmap is stored top-to-bottom pos=bmpImageoffset+row*rowSize; if(bmpFile.position()!=pos){// Need seek? bmpFile.seek(pos); buffidx=sizeof(sdbuffer);// Force buffer reload }   for(col=0;colw;col++){// For each column... // Time to read more pixel data? if(buffidx>=sizeof(sdbuffer)){// Indeed // Push LCD buffer to the display first if(lcdidx>0){ tft.pushColors(lcdbuffer,lcdidx,first); lcdidx=0; first=false; } bmpFile.read(sdbuffer,sizeof(sdbuffer)); buffidx=0;// Set index to beginning }   // Convert pixel from BMP to TFT format b=sdbuffer[buffidx++]; g=sdbuffer[buffidx++]; r=sdbuffer[buffidx++]; lcdbuffer[lcdidx++]=tft.color565(r,g,b); }// end pixel }// end scanline     // Write any remaining data to LCD if(lcdidx>0){ tft.pushColors(lcdbuffer,lcdidx,first); } //Serial.print(F("Loaded in ")); //Serial.print(millis() - startTime); //Serial.println(" ms"); }// end goodBmp } }     bmpFile.close(); //if (!goodBmp) Serial.println(F("BMP format not recognized.")); } uint16_t read16(Filef){ uint16_t result; ((uint8_t*)&result)[0]=f.read();// LSB ((uint8_t*)&result)[1]=f.read();// MSB returnresult; } uint32_t read32(Filef){ uint32_t result; ((uint8_t*)&result)[0]=f.read();// LSB ((uint8_t*)&result)[1]=f.read(); ((uint8_t*)&result)[2]=f.read(); ((uint8_t*)&result)[3]=f.read();// MSB returnresult; }
 
فیلم پروژه بالا رو هم در زیر میبینید(بازم شرمنده بابت کیفیت پایین اگه کسی میتونه فیلم بگیره و بفرسته )
http://www.aparat.com/v/N7DW4 3)  پروژه نقاشی با آردوینو
تو این پروژه از کتابخونه صفحه تاچ هم استفاده کردیم، که در بالا این کتابخونه صفحه تاچ رو توضیح نداده بودم، بعد از این پروژه توضیحش میدم و انشاالله اگه حسش بود برا اونم یه چند تا پروژه میزارم تو سایت.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 #include #include MCUFRIEND_kbv tft; #include     // most mcufriend shields use these pins and Portrait mode: uint8_t YP=A1;// must be an analog pin, use "An" notation! uint8_t XM=A2;// must be an analog pin, use "An" notation! uint8_t YM=7;// can be a digital pin uint8_t XP=6;// can be a digital pin uint8_t SwapXY=0;   uint16_t TS_LEFT=920; uint16_t TS_RT=150; uint16_t TS_TOP=940; uint16_t TS_BOT=120;   // For better pressure precision, we need to know the resistance // between X+ and X- Use any multimeter to read it // For the one we're using, its 300 ohms across the X plate TouchScreen ts=TouchScreen(XP,YP,XM,YM,300); TSPoint tp;   #define MINPRESSURE 20 #define MAXPRESSURE 1000   #define SWAP(a, b) {uint16_t tmp = a; a = b; b = tmp;}   int16_t BOXSIZE; int16_t PENRADIUS=3; uint16_t identifier,oldcolor,currentcolor; uint8_t Orientation=0;//PORTRAIT   // 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   voidsetup(void){   uint16_t tmp; tft.begin(9600);   tft.reset(); identifier=tft.readID(); TS_LEFT=920;TS_RT=139;TS_TOP=944;TS_BOT=150;   SwapXY=0;     ts=TouchScreen(XP,YP,XM,YM,300); tft.begin(identifier); tft.setRotation(0); tft.fillScreen(BLACK);   BOXSIZE=tft.width()/6; tft.fillScreen(BLACK);   tft.fillRect(0,0,BOXSIZE,BOXSIZE,RED); tft.fillRect(BOXSIZE,0,BOXSIZE,BOXSIZE,YELLOW); tft.fillRect(BOXSIZE*2,0,BOXSIZE,BOXSIZE,GREEN); tft.fillRect(BOXSIZE*3,0,BOXSIZE,BOXSIZE,CYAN); tft.fillRect(BOXSIZE*4,0,BOXSIZE,BOXSIZE,BLUE); tft.fillRect(BOXSIZE*5,0,BOXSIZE,BOXSIZE,MAGENTA);   tft.drawRect(0,0,BOXSIZE,BOXSIZE,WHITE); currentcolor=RED; }   voidloop(){   uint16_t xpos,ypos;//screen coordinates tp=ts.getPoint();//tp.x, tp.y are ADC values   // if sharing pins, you'll need to fix the directions of the touchscreen pins pinMode(XM,OUTPUT); pinMode(YP,OUTPUT); pinMode(XP,OUTPUT); pinMode(YM,OUTPUT); // digitalWrite(XM, HIGH); // digitalWrite(YP, HIGH); // we have some minimum pressure we consider 'valid' // pressure of 0 means no pressing!   if(tp.z>MINPRESSURE&&tp.zMAXPRESSURE){ // is controller wired for Landscape ? or are we oriented in Landscape? if(SwapXY!=(Orientation&1))SWAP(tp.x,tp.y); // scale from 0->1023 to tft.width i.e. left = 0, rt = width // most mcufriend have touch (with icons) that extends below the TFT // screens without icons need to reserve a space for "erase" // scale the ADC values from ts.getPoint() to screen values e.g. 0-239 xpos=map(tp.x,TS_LEFT,TS_RT,0,tft.width()); ypos=map(tp.y,TS_TOP,TS_BOT,0,tft.height());   // are we in top color box area ? if(yposBOXSIZE){//draw white border on selected color box oldcolor=currentcolor;   if(xposBOXSIZE){ currentcolor=RED; tft.drawRect(0,0,BOXSIZE,BOXSIZE,WHITE); }elseif(xposBOXSIZE*2){ currentcolor=YELLOW; tft.drawRect(BOXSIZE,0,BOXSIZE,BOXSIZE,WHITE); }elseif(xposBOXSIZE*3){ currentcolor=GREEN; tft.drawRect(BOXSIZE*2,0,BOXSIZE,BOXSIZE,WHITE); }elseif(xposBOXSIZE*4){ currentcolor=CYAN; tft.drawRect(BOXSIZE*3,0,BOXSIZE,BOXSIZE,WHITE); }elseif(xposBOXSIZE*5){ currentcolor=BLUE; tft.drawRect(BOXSIZE*4,0,BOXSIZE,BOXSIZE,WHITE); }elseif(xposBOXSIZE*6){ currentcolor=MAGENTA; tft.drawRect(BOXSIZE*5,0,BOXSIZE,BOXSIZE,WHITE); }   if(oldcolor!=currentcolor){//rub out the previous white border if(oldcolor==RED)tft.fillRect(0,0,BOXSIZE,BOXSIZE,RED); if(oldcolor==YELLOW)tft.fillRect(BOXSIZE,0,BOXSIZE,BOXSIZE,YELLOW); if(oldcolor==GREEN)tft.fillRect(BOXSIZE*2,0,BOXSIZE,BOXSIZE,GREEN); if(oldcolor==CYAN)tft.fillRect(BOXSIZE*3,0,BOXSIZE,BOXSIZE,CYAN); if(oldcolor==BLUE)tft.fillRect(BOXSIZE*4,0,BOXSIZE,BOXSIZE,BLUE); if(oldcolor==MAGENTA)tft.fillRect(BOXSIZE*5,0,BOXSIZE,BOXSIZE,MAGENTA); } } // are we in drawing area ? if(((ypos-PENRADIUS)>BOXSIZE)&&((ypos+PENRADIUS)tft.height())){ tft.fillCircle(xpos,ypos,PENRADIUS,currentcolor); } // are we in erase area ? if(ypos>tft.height()-10){ // press the bottom of the screen to erase tft.fillRect(0,BOXSIZE,tft.width(),tft.height()-BOXSIZE,BLACK); } } }
 
اینم از فیلم پروژه(بازم با وب کم فیلم گرفتم )
http://www.aparat.com/v/dkGWS
 
  دانلود چیز میزای پروژه آردوینو این مطلب !
دانلود پروژه ها و عکس ها و کتابخونه های مورد نیاز این مطلب – سرور1
دانلود پروژه ها و عکس ها و کتابخونه های مورد نیاز این مطلب – سرور2
 
 
چیزایی که من نگفتم 
به علت این که من وقت ندارم!!! بیش از این نمیتونم توضیح بدم، بقیش بمونه برای بعد توضیح توابع صفحه تاچ و چند پروژه ازش نحوه ساخت و تغییر فوت
 
 
مطالب مرتبط   
How to display images on 2.4inch TFT and make it a digital photoframe
 
آموزش و پروژه نمایشگر های دیگه با آردوینو :
آموزش نمایشگر گرافیکی ks0108 با arduino جلسه1
آموزش نمایشگر گرافیکی ks0108 با arduino جلسه2
آموزش جامع کار با lcd کاراکتری در ARDUINO پروژه و آموزش راه اندازی lcd tft 1.8 inch با آردوینو
پروژه و آموزش راه اندازی lcd nokia 5110 با arduino