欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4904|回復(fù): 33
打印 上一主題 下一主題
收起左側(cè)

esp32利用Arduino_GFX_Library庫(kù)顯示圖片問(wèn)題

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
好兄弟們,我在用esp32c3讀取SD卡中圖片并顯示到tft1.8屏幕上,單獨(dú)一張圖片顯示正常顯示,但是循環(huán)一組圖片時(shí),就一直顯示第一張圖片。代碼貼到下面
///////////////////////////////////////代碼開(kāi)始///////////////////////////////////////////////
  1. #include <SPI.h>
  2. #include <mySD.h>
  3. #include <Arduino_GFX_Library.h>
  4. #include<String.h>
  5. ext::File bmpFile;
  6. unsigned short pic[0x5000]; // 128*160圖像0x5000像素
  7. byte aByte;                 // 1字節(jié)數(shù)據(jù)
  8. /*******重復(fù)播放圖片所需變量*******************************/
  9. char* aa[]={"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp"};
  10. unsigned int bmp;
  11. /******************************************************/
  12. Arduino_DataBus *bus = new Arduino_ESP32SPI(5 /* DC */, 7 /* CS */, 2 /* SCK */, 3 /* MOSI */);
  13. Arduino_GFX *gfx = new Arduino_ST7735(bus, 4 /* RST */, 2 /* 旋轉(zhuǎn)屏幕180度 */, false);

  14. void setup()
  15. {
  16.     Serial.begin(115200);
  17.     //從SD卡讀取圖片
  18.     SD.begin(6, 3, 10, 2);
  19. }
  20. void loop()
  21. {
  22.    for(bmp=0;bmp<5;bmp++){
  23.    bmpFile = SD.open(aa[bmp], FILE_READ);
  24.    if (bmpFile){
  25.         //顯示圖片
  26.         while (bmpFile.available())
  27.         {
  28.             //跳過(guò)前0x36個(gè)字節(jié)的頭
  29.             for (int i = 0; i < 0x36; i++)
  30.             {
  31.                 Serial.print(bmpFile.read(), HEX);
  32.             }
  33.             //把rgb24轉(zhuǎn)換成rgb16
  34.             for (int i = 0; i < 0x5000; i++)
  35.             {
  36.                 aByte = bmpFile.read();
  37.                 pic[i] = (aByte * 32 / 256) << 11;
  38.                 aByte = bmpFile.read();
  39.                 pic[i] |= (aByte * 64 / 256) << 5;
  40.                 aByte = bmpFile.read();
  41.                 pic[i] |= (aByte * 32 / 256);
  42.             }
  43.         }
  44.        bmpFile.close();
  45.     }
  46.     //顯示圖片
  47.     gfx->begin();
  48.     gfx->fillScreen(WHITE);
  49.     gfx->draw16bitRGBBitmap(0, 0, pic, 128, 160);
  50.     delay(100);
  51.   }
  52. }
復(fù)制代碼
///////////////////////////////////////代碼結(jié)束///////////////////////////////////////////////
就是這句bmpFile = SD.open(aa[bmp], FILE_READ);,我aa[]數(shù)組放的是圖片的名稱(chēng):{"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp"},當(dāng)寫(xiě)為aa[0]時(shí),顯示的是"1.bmp"這張圖片,是正確的。但是用循環(huán) for(bmp=0;bmp<5;bmp++),然后aa[bmp]時(shí),只會(huì)顯示第一張圖片5次,而不會(huì)顯示"2.bmp","3.bmp","4.bmp","5.bmp",各位好兄弟有什么想法嗎?
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:1063483 發(fā)表于 2023-2-21 14:48 | 只看該作者
<SPI.h>
<mySD.h>
<Arduino_GFX_Library.h>
<String.h>
如果可以把這幾個(gè)頭文件提供一下,愿意幫你調(diào)試一下
回復(fù)

使用道具 舉報(bào)

板凳
ID:891089 發(fā)表于 2023-2-21 15:30 來(lái)自觸屏版 | 只看該作者
watsonbu 發(fā)表于 2023-2-21 14:48
如果可以把這幾個(gè)頭文件提供一下,愿意幫你調(diào)試一下

謝謝好兄弟,spi.h和string.h是自帶庫(kù),其他兩個(gè)我怎么發(fā)給你?
回復(fù)

使用道具 舉報(bào)

地板
ID:384109 發(fā)表于 2023-2-21 16:26 | 只看該作者
可以先不用數(shù)組,直接把顯示圖片部分重復(fù)五次,每次開(kāi)不同的圖片,就可以確定問(wèn)題點(diǎn)了
回復(fù)

使用道具 舉報(bào)

5#
ID:891089 發(fā)表于 2023-2-21 16:33 來(lái)自觸屏版 | 只看該作者
人中狼 發(fā)表于 2023-2-21 16:26
可以先不用數(shù)組,直接把顯示圖片部分重復(fù)五次,每次開(kāi)不同的圖片,就可以確定問(wèn)題點(diǎn)了

這個(gè)方法也試過(guò),我是把顯示部分復(fù)制了兩次,結(jié)果是第一張圖片顯示了兩次。刷新函數(shù)也有,我就想不通是哪里出現(xiàn)了問(wèn)題,你可以看下我的程序,我是把顯示部分除了gfx變量的所有變量都新定義了新變量,gfx是屏幕引腳定義變量,我覺(jué)得應(yīng)該不是這個(gè)方法問(wèn)題。
回復(fù)

使用道具 舉報(bào)

6#
ID:1063483 發(fā)表于 2023-2-21 17:18 | 只看該作者
就在黑51發(fā)消息給我就可以了
回復(fù)

使用道具 舉報(bào)

7#
ID:891089 發(fā)表于 2023-2-21 17:45 來(lái)自觸屏版 | 只看該作者
watsonbu 發(fā)表于 2023-2-21 17:18
就在黑51發(fā)消息給我就可以了

我手機(jī)沒(méi)看到怎么發(fā)文件給你,是要用電腦發(fā)給你嗎?
回復(fù)

使用道具 舉報(bào)

8#
ID:384109 發(fā)表于 2023-2-21 17:49 | 只看該作者
美琴的備胎 發(fā)表于 2023-2-21 16:33
這個(gè)方法也試過(guò),我是把顯示部分復(fù)制了兩次,結(jié)果是第一張圖片顯示了兩次。刷新函數(shù)也有,我就想不通是哪 ...

我的意思是這里bmpFile = SD.open(aa[bmp], FILE_READ);不用數(shù)組,看代碼應(yīng)該是這個(gè)函數(shù)調(diào)用的問(wèn)題,只打開(kāi)了一個(gè)文件,可以查查這個(gè)函數(shù)的具體用法和參數(shù)要求。
回復(fù)

使用道具 舉報(bào)

9#
ID:384109 發(fā)表于 2023-2-21 17:51 | 只看該作者
美琴的備胎 發(fā)表于 2023-2-21 16:33
這個(gè)方法也試過(guò),我是把顯示部分復(fù)制了兩次,結(jié)果是第一張圖片顯示了兩次。刷新函數(shù)也有,我就想不通是哪 ...

還有一個(gè)已經(jīng)打開(kāi)的文件,在開(kāi)第二個(gè)文件時(shí)是否需要關(guān)閉的問(wèn)題
回復(fù)

使用道具 舉報(bào)

10#
ID:891089 發(fā)表于 2023-2-21 18:55 | 只看該作者
人中狼 發(fā)表于 2023-2-21 17:49
我的意思是這里bmpFile = SD.open(aa, FILE_READ);不用數(shù)組,看代碼應(yīng)該是這個(gè)函數(shù)調(diào)用的問(wèn)題,只打開(kāi)了 ...

這個(gè)原始程序就是bmpFile = SD.open(“1.bmp”, FILE_READ);,我改成數(shù)組調(diào)用了,aa[0]的話也是可以正常顯示的,我試過(guò)了
回復(fù)

使用道具 舉報(bào)

11#
無(wú)效樓層,該帖已經(jīng)被刪除
12#
ID:891089 發(fā)表于 2023-2-21 18:58 | 只看該作者
人中狼 發(fā)表于 2023-2-21 17:51
還有一個(gè)已經(jīng)打開(kāi)的文件,在開(kāi)第二個(gè)文件時(shí)是否需要關(guān)閉的問(wèn)題

bmpFile.close();  有的,要關(guān)的
回復(fù)

使用道具 舉報(bào)

13#
ID:891089 發(fā)表于 2023-2-21 19:24 | 只看該作者
#include <SPI.h>
#include <mySD.h>
#include <Arduino_GFX_Library.h>
#include<String.h>
ext::File bmpFile,bmpFile1;
unsigned short pic[0x5000],pic1[0x5000]; // 128*160圖像0x5000像素
byte aByte,aByte1;                 // 1字節(jié)數(shù)據(jù)
/*******重復(fù)播放圖片所需變量*******************************/
char* aa[]={"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp"};
unsigned int bmp;
/******************************************************/
Arduino_DataBus *bus = new Arduino_ESP32SPI(5 /* DC */, 7 /* CS */, 2 /* SCK */, 3 /* MOSI */);
Arduino_GFX *gfx = new Arduino_ST7735(bus, 4 /* RST */, 2 /* 旋轉(zhuǎn)屏幕180度 */, false);

void setup()
{
    Serial.begin(115200);
    //從SD卡讀取圖片
    SD.begin(6, 3, 10, 2);
}
void loop()
{
   //for(bmp=0;bmp<5;bmp++){
   bmpFile = SD.open(/*aa[bmp]*/"1.bmp", FILE_READ);
   if (bmpFile){
        //顯示圖片
        while (bmpFile.available())
        {
            //跳過(guò)前0x36個(gè)字節(jié)的頭
            for (int i = 0; i < 0x36; i++)
            {
                Serial.print(bmpFile.read(), HEX);
            }
            //把rgb24轉(zhuǎn)換成rgb16
            for (int i = 0; i < 0x5000; i++)
            {
                aByte = bmpFile.read();
                pic[i] = (aByte * 32 / 256) << 11;
                aByte = bmpFile.read();
                pic[i] |= (aByte * 64 / 256) << 5;
                aByte = bmpFile.read();
                pic[i] |= (aByte * 32 / 256);
            }
        }  
       bmpFile.close();
   }


    bmpFile1 = SD.open(/*aa[bmp]*/"2.bmp", FILE_READ);
   if (bmpFile1){
        //顯示圖片
        while (bmpFile1.available())
        {
            //跳過(guò)前0x36個(gè)字節(jié)的頭
            for (int i = 0; i < 0x36; i++)
            {
                Serial.print(bmpFile1.read(), HEX);
            }
            //把rgb24轉(zhuǎn)換成rgb16
            for (int i = 0; i < 0x5000; i++)
            {
                aByte1 = bmpFile1.read();
                pic1[i] = (aByte1 * 32 / 256) << 11;
                aByte1 = bmpFile1.read();
                pic1[i] |= (aByte1 * 64 / 256) << 5;
                aByte1 = bmpFile1.read();
                pic1[i] |= (aByte1 * 32 / 256);
            }
        }  
       bmpFile1.close();
   }

   
    //顯示圖片
    gfx->begin();
    gfx->fillScreen(WHITE);
    gfx->draw16bitRGBBitmap(0, 0, pic, 128, 160);
    delay(100);
    gfx->draw16bitRGBBitmap(0, 0, pic1, 128, 160);
    delay(100);
   //}
}
這樣寫(xiě)代碼,可以兩個(gè)圖片循環(huán)顯示了
回復(fù)

使用道具 舉報(bào)

14#
ID:384109 發(fā)表于 2023-2-21 20:12 | 只看該作者
返回一下文件打開(kāi)狀態(tài)吧,如果if (bmpFile)這個(gè)不成立的話,顯示數(shù)據(jù)pic[ i] 不會(huì)改變,應(yīng)該就還是之前打開(kāi)文件的數(shù)據(jù),問(wèn)題應(yīng)該還是在文件的打開(kāi)上,后面的文件都沒(méi)有成功打開(kāi),只打開(kāi)了第一個(gè)
回復(fù)

使用道具 舉報(bào)

15#
ID:1063483 發(fā)表于 2023-2-21 21:27 | 只看該作者
你的程序有個(gè)小問(wèn)題,從頭到尾再找吧。

ESP32.PNG (30.6 KB, 下載次數(shù): 75)

可能程序有點(diǎn)小問(wèn)題

可能程序有點(diǎn)小問(wèn)題
回復(fù)

使用道具 舉報(bào)

16#
ID:384109 發(fā)表于 2023-2-21 22:28 | 只看該作者

aa[]定義錯(cuò)誤,https://blog.csdn.net/qiaoermeng/article/details/88366250,可以看看這里的解釋
回復(fù)

使用道具 舉報(bào)

17#
ID:1063483 發(fā)表于 2023-2-21 22:31 | 只看該作者
修改了如下,不知道能不能成功

#include <SPI.h>
#include <mySD.h>
#include <Arduino_GFX_Library.h>
#include<String.h>
ext::File bmpFile;
unsigned short pic[0x5000]; // 128*160圖像0x5000像素
byte aByte;                 // 1字節(jié)數(shù)據(jù)
/*******重復(fù)播放圖片所需變量*******************************/
char* aa[5]={"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp"};
unsigned int bmp;
/******************************************************/
Arduino_DataBus *bus = new Arduino_ESP32SPI(5 /* DC */, 7 /* CS */, 2 /* SCK */, 3 /* MOSI */);
Arduino_GFX *gfx = new Arduino_ST7735(bus, 4 /* RST */, 2 /* 旋轉(zhuǎn)屏幕180度 */, false);

void setup()
{
    Serial.begin(115200);
    //從SD卡讀取圖片
    SD.begin(6, 3, 10, 2);
}
void loop()
{
   for(bmp=0;bmp<5;bmp++){
   bmpFile = SD.open(aa[bmp], FILE_READ);
   if (bmpFile){
        //顯示圖片
        while (bmpFile.available())
        {
            //跳過(guò)前0x36個(gè)字節(jié)的頭
            for (int i = 0; i < 0x36; i++)
            {
                Serial.print(bmpFile.read(), HEX);
            }
            //把rgb24轉(zhuǎn)換成rgb16
            for (int i = 0; i < 0x5000; i++)
            {
                aByte = bmpFile.read();
                pic[i] = (aByte * 32 / 256) << 11;
                aByte = bmpFile.read();
                pic[i] |= (aByte * 64 / 256) << 5;
                aByte = bmpFile.read();
                pic[i] |= (aByte * 32 / 256);
            }
        }
        /***********************************/
       if (++bmp == 5)
       bmp = 0;          //計(jì)數(shù)復(fù)位
       /***********************************/
       bmpFile.close();
      
      // bmpFile.delete();//試試不行再加這句再試試***********
    }
    //顯示圖片
    gfx->begin();
    gfx->fillScreen(WHITE);
    gfx->draw16bitRGBBitmap(0, 0, pic, 128, 160);
   
    delay(100);//前面修改完還不行 ,改為delay(1000)試試************
  }
}
回復(fù)

使用道具 舉報(bào)

18#
ID:891089 發(fā)表于 2023-2-21 22:40 | 只看該作者
watsonbu 發(fā)表于 2023-2-21 21:27
你的程序有個(gè)小問(wèn)題,從頭到尾再找吧。

好兄弟,你這是缺了sd卡的庫(kù),這是地址github.com/nhatuan84/esp32-micro-sdcard/blob/master/mySD.h
回復(fù)

使用道具 舉報(bào)

19#
ID:891089 發(fā)表于 2023-2-21 23:00 | 只看該作者
人中狼 發(fā)表于 2023-2-21 22:28
aa[]定義錯(cuò)誤,https://blog.csdn.net/qiaoermeng/article/details/88366250,可以看看這里的解釋

我程序改成這樣了

String aa[]={"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp"};
*****
   for(bmp=0;bmp<5;bmp++){
   bmpFile = SD.open(aa[bmp].c_str(), FILE_READ);
******
最后輸出了下 :
Serial.println(aa[bmp].c_str());

這是輸出內(nèi)容:
22:57:37.539 -> 5.bmp
22:57:38.886 -> 1.bmp
22:57:40.249 -> 2.bmp
22:57:41.615 -> 3.bmp
22:57:42.996 -> 4.bmp
22:57:44.372 -> 5.bmp
22:57:45.722 -> 1.bmp
22:57:47.085 -> 2.bmp
22:57:48.454 -> 3.bmp
22:57:49.842 -> 4.bmp
22:57:51.227 -> 5.bmp
22:57:52.575 -> 1.bmp
22:57:53.966 -> 2.bmp
22:57:55.316 -> 3.bmp
22:57:56.697 -> 4.bmp
22:57:58.031 -> 5.bmp
22:57:59.404 -> 1.bmp
22:58:00.797 -> 2.bmp
22:58:02.164 -> 3.bmp
確實(shí)已經(jīng)寫(xiě)入文件名了,但是顯示屏還是只顯示第一張圖片
回復(fù)

使用道具 舉報(bào)

20#
ID:384109 發(fā)表于 2023-2-21 23:12 | 只看該作者
這個(gè)不熟,不過(guò)看代碼SD.open(/*aa[bmp]*/"2.bmp", FILE_READ);,串口的輸出似乎少了雙引號(hào),看現(xiàn)象就是pic[]的數(shù)據(jù)沒(méi)更新,也就是if (bmpFile)不成立
回復(fù)

使用道具 舉報(bào)

21#
ID:1063483 發(fā)表于 2023-2-21 23:20 | 只看該作者
#include <SPI.h>
#include <mySD.h>
#include <Arduino_GFX_Library.h>
#include<String.h>
ext::File bmpFile;
unsigned short pic[0x5000]; // 128*160圖像0x5000像素
byte aByte;                 // 1字節(jié)數(shù)據(jù)
/*******重復(fù)播放圖片所需變量*******************************/
char* aa[5]={"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp"};
unsigned int bmp;
/******************************************************/
Arduino_DataBus *bus = new Arduino_ESP32SPI(5 /* DC */, 7 /* CS */, 2 /* SCK */, 3 /* MOSI */);
Arduino_GFX *gfx = new Arduino_ST7735(bus, 4 /* RST */, 2 /* 旋轉(zhuǎn)屏幕180度 */, false);

void setup()
{
    Serial.begin(115200);
    //從SD卡讀取圖片
    SD.begin(6, 3, 10, 2);
}
void loop()
{
   for(bmp=0;bmp<5;bmp++){
   bmpFile = SD.open(aa[bmp], FILE_READ);
   if (bmpFile){
        //顯示圖片
        while (bmpFile.available())
        {
            //跳過(guò)前0x36個(gè)字節(jié)的頭
            for (int i = 0; i < 0x36; i++)
            {
                Serial.print(bmpFile.read(), HEX);
            }
            //把rgb24轉(zhuǎn)換成rgb16
            for (int i = 0; i < 0x5000; i++)
            {
                aByte = bmpFile.read();
                pic[i] = (aByte * 32 / 256) << 11;
                aByte = bmpFile.read();
                pic[i] |= (aByte * 64 / 256) << 5;
                aByte = bmpFile.read();
                pic[i] |= (aByte * 32 / 256);
            }
        }
        /***********************************/
       if (++bmp == 5)
       bmp = 0;          //計(jì)數(shù)復(fù)位
       /***********************************/
       bmpFile.close();
      
      // bmpFile.delete();//試試不行再加這句***********
    }
    //顯示圖片
    gfx->begin();
    gfx->fillScreen(WHITE);
    gfx->draw16bitRGBBitmap(0, 0, pic, 128, 160);
   
    delay(100);//前面修改完還不行 ,改為delay(1000)試試************
  }
}
回復(fù)

使用道具 舉報(bào)

22#
ID:891089 發(fā)表于 2023-2-22 12:26 | 只看該作者
watsonbu 發(fā)表于 2023-2-21 23:20
#include
#include
#include

只加
/***********************************/
       if (++bmp == 5)
       bmp = 0;          //計(jì)數(shù)復(fù)位
/***********************************/
也不行
  bmpFile.delete(); 也不行,會(huì)報(bào)錯(cuò)expected unqualified-id before 'delete'
回復(fù)

使用道具 舉報(bào)

23#
ID:1063483 發(fā)表于 2023-2-22 12:41 | 只看該作者
“ext::File bmpFile;”
這里能改成指針?類(lèi)似    ext::File  * bmpFile;
之后只加和不加兩種:
/***********************************/
       if (++bmp == 5)
       bmp = 0;          //計(jì)數(shù)復(fù)位
/***********************************/
試試?有Bug,就是如此令人不愉快
回復(fù)

使用道具 舉報(bào)

24#
ID:891089 發(fā)表于 2023-2-22 12:56 | 只看該作者
watsonbu 發(fā)表于 2023-2-22 12:41
“ext::File bmpFile;”
這里能改成指針?類(lèi)似    ext::File  * bmpFile;
之后只加和不加兩種:

試過(guò)了,會(huì)報(bào)錯(cuò),我都在考慮換個(gè)顯示庫(kù)了,有推薦嗎?
回復(fù)

使用道具 舉報(bào)

25#
ID:1063483 發(fā)表于 2023-2-22 13:04 | 只看該作者
“unsigned short pic[0x5000]; // 128*160圖像0x5000像素”
這邊有這樣的問(wèn)題,調(diào)試出錯(cuò)說(shuō), pic[0x5000]的0x5000太大。

如果考慮這些之后不行,是不是要考慮 LINUX 調(diào)試ESP32了?但是配置完 LINUX 之后,真的不推薦。
看你的程序很清晰的,似乎還是沒(méi)有循環(huán)讀進(jìn)來(lái)。很久以前也感同身受,慢慢折騰,也許得來(lái)全不費(fèi)工夫。

還有一個(gè)可能解決問(wèn)題的辦法,找一找 ESP32的供應(yīng)商,他們有專(zhuān)門(mén)的售后軟件工程師,當(dāng)時(shí)好像跟他們一起,才把問(wèn)題解決掉。但是他們就是用的 LINUX 調(diào)試和燒錄的,搞好之后,不要用LINUX 燒錄,太慢了!直接用他們的串口軟件燒錄挺快的。
回復(fù)

使用道具 舉報(bào)

26#
ID:978267 發(fā)表于 2023-2-22 14:22 | 只看該作者
安信可軟件怎么編譯三元組
回復(fù)

使用道具 舉報(bào)

27#
ID:384109 發(fā)表于 2023-2-22 16:30 | 只看該作者
美琴的備胎 發(fā)表于 2023-2-21 23:00
我程序改成這樣了

String aa[]={"1.bmp","2.bmp","3.bmp","4.bmp","5.bmp"};

你這里應(yīng)該是在bmpFile = SD.open(aa[bmp].c_str(), FILE_READ);后看bmpFile的值,現(xiàn)在串口輸出的只是數(shù)組aa[]的內(nèi)容而已,并不是打開(kāi)文件是否成功的結(jié)果
回復(fù)

使用道具 舉報(bào)

28#
ID:1063483 發(fā)表于 2023-2-22 17:53 | 只看該作者
。。。。
SD.begin(6, 3, 10, 2);
}

void clear_buffer(){                         //緩存清除,返回-1,緩存清除。
while(Serial.read()>=0);
}
。。。。。
  gfx->draw16bitRGBBitmap(0, 0, pic, 128, 160);
    delay(1000);
    clear_buffeer();//調(diào)用清掉前一緩存
  }
}
回復(fù)

使用道具 舉報(bào)

29#
ID:419909 發(fā)表于 2023-2-23 06:50 | 只看該作者
路過(guò)。順便問(wèn)一下。Arduino_GFX_Library用這個(gè)庫(kù)后,編譯速度是不是 很慢。大概多長(zhǎng)時(shí)間?
回復(fù)

使用道具 舉報(bào)

30#
ID:891089 發(fā)表于 2023-2-23 14:32 來(lái)自觸屏版 | 只看該作者
watsonbu 發(fā)表于 2023-2-22 17:53
。。。。
SD.begin(6, 3, 10, 2);
}

    gfx->fillScreen(WHITE);
這一句就是刷新
回復(fù)

使用道具 舉報(bào)

31#
ID:891089 發(fā)表于 2023-2-23 14:33 來(lái)自觸屏版 | 只看該作者
wfqxgw 發(fā)表于 2023-2-23 06:50
路過(guò)。順便問(wèn)一下。Arduino_GFX_Library用這個(gè)庫(kù)后,編譯速度是不是 很慢。大概多長(zhǎng)時(shí)間?

嗯…我不知道是不是因?yàn)檫@個(gè)庫(kù)的原因,我感覺(jué)esp32編譯都很慢
回復(fù)

使用道具 舉報(bào)

32#
ID:1063483 發(fā)表于 2023-2-24 13:18 | 只看該作者
“esp32編譯都很慢”
是arduino慢,特別是大一點(diǎn)的程序,里面啰啰嗦嗦一堆
回復(fù)

使用道具 舉報(bào)

33#
ID:891089 發(fā)表于 2023-2-24 19:34 | 只看該作者
問(wèn)題解決了,用TFT_espi庫(kù),源程序放下面:
//程序開(kāi)始
/*
*@功能:ESP32讀取SD卡圖片顯示在1.14IPS屏幕上
*@作者:劉澤文
*@時(shí)間:2020/3/27
*/

//引用相關(guān)庫(kù)
#include <SD.h>
#include <FS.h>
#include <SPI.h>
#include <TFT_eSPI.h>
#include <JPEGDecoder.h>


#define DEBUG

#ifdef DEBUG
#define DebugPrintln(message) Serial.println(message)
#else
#define DebugPrintln(message)
#endif

#ifdef DEBUG
#define DebugPrint(message) Serial.print(message)
#else
#define DebugPrint(message)
#endif

TFT_eSPI tft = TFT_eSPI(128, 160); // Invoke custom library
SPIClass sdSPI(VSPI);
#define SD_MISO     10
#define SD_MOSI     3
#define SD_SCLK     2
#define SD_CS       9

void drawSdJpeg(const char *filename, int xpos, int ypos);
void jpegRender(int xpos, int ypos);
void jpegInfo();
void showTime(uint32_t msTime);
void SD_read_Time(uint32_t msTime);

void setup()
{
  Serial.begin(9600);
  DebugPrintln();

  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_WHITE);
  tft.setTextSize(1);
  tft.setTextColor(TFT_MAGENTA);
  tft.setCursor(0, 0);
  tft.setTextDatum(MC_DATUM);
  tft.setTextSize(1);
  tft.setSwapBytes(true);
  delay(500);

  if (TFT_BL > 0) { // TFT_BL has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h
     pinMode(TFT_BL, OUTPUT); // Set backlight pin to output mode
     digitalWrite(TFT_BL, 1); // TFT_BACKLIGHT_ONTurn backlight on. TFT_BACKLIGHT_ON has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h
   }
  
  //掛載文件系統(tǒng)
  sdSPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);
  if (!SD.begin(SD_CS, sdSPI))
  {
    DebugPrintln("存儲(chǔ)卡掛載失敗");
    return;
  }
  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE)
  {
    DebugPrintln("未連接存儲(chǔ)卡");
    return;
  }
  else if (cardType == CARD_MMC)
  {
    DebugPrintln("掛載了MMC卡");
  }
  else if (cardType == CARD_SD)
  {
    DebugPrintln("掛載了SDSC卡");
  }
  else if (cardType == CARD_SDHC)
  {
    DebugPrintln("掛載了SDHC卡");
  }
  else
  {
    DebugPrintln("掛載了未知存儲(chǔ)卡");
  }

  //打印存儲(chǔ)卡信息
  Serial.printf("存儲(chǔ)卡總大小是: %lluMB \n", SD.cardSize() / (1024 * 1024)); // "/ (1024 * 1024)"可以換成">> 20"
  Serial.printf("文件系統(tǒng)總大小是: %lluB \n", SD.totalBytes());
  Serial.printf("文件系統(tǒng)已用大小是: %lluB \n", SD.usedBytes());
}

void loop() {
/*
  //測(cè)試壁紙
  for(int image_num = 1;image_num<=6;image_num++){
    char FileName[10];
    sprintf(FileName,"%d.jpg",image_num);
    drawSdJpeg(FileName, 0, 0);     // This draws a jpeg pulled off the SD Card
    delay(500);
  }
*/
  //播放badapple,共6540幀,每秒30幀
  for(int image_num = 1;image_num<=2;image_num+=1){
    char FileName[10];
    sprintf(FileName,"/%d.jpg",image_num);
    //drawSdJpeg(FileName, 0, 0);     // This draws a jpeg pulled off the SD Card
    drawSdJpeg(FileName, 0, 0);
    delay(100);
  }

}

void drawSdJpeg(const char *filename, int xpos, int ypos) {
  uint32_t readTime = millis();
  // Open the named file (the Jpeg decoder library will close it)
  File jpegFile = SD.open( filename, FILE_READ);  // or, file handle reference for SD library

  if ( !jpegFile ) {
    DebugPrint("ERROR: File \"");
    DebugPrint(jpegFile);
    DebugPrintln ("\" not found!");
    return;
  }

  DebugPrintln("===========================");
  DebugPrint("Drawing file: "); DebugPrintln(filename);
  DebugPrintln("===========================");

  // Use one of the following methods to initialise the decoder:
  boolean decoded = JpegDec.decodeSdFile(jpegFile);  // Pass the SD file handle to the decoder,
  //boolean decoded = JpegDec.decodeSdFile(filename);  // or pass the filename (String or character array)
  SD_read_Time(millis() - readTime);

  if (decoded) {
    // print information about the image to the serial port
    jpegInfo();
    // render the image onto the screen at given coordinates
    jpegRender(xpos, ypos);
  }
  else {
    DebugPrintln("Jpeg file format not supported!");
  }
}

//####################################################################################################
// Draw a JPEG on the TFT, images will be cropped on the right/bottom sides if they do not fit
//####################################################################################################
// This function assumes xpos,ypos is a valid screen coordinate. For convenience images that do not
// fit totally on the screen are cropped to the nearest MCU size and may leave right/bottom borders.
void jpegRender(int xpos, int ypos) {
  // record the current time so we can measure how long it takes to draw an image
  uint32_t drawTime = millis();

  //jpegInfo(); // Print information from the JPEG file (could comment this line out)

  uint16_t *pImg;
  uint16_t mcu_w = JpegDec.MCUWidth;
  uint16_t mcu_h = JpegDec.MCUHeight;
  uint32_t max_x = JpegDec.width;
  uint32_t max_y = JpegDec.height;

  bool swapBytes = tft.getSwapBytes();
  tft.setSwapBytes(true);
  
  // Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)
  // Typically these MCUs are 16x16 pixel blocks
  // Determine the width and height of the right and bottom edge image blocks
  uint32_t min_w = (mcu_w<(max_x % mcu_w)?mcu_w:(max_x % mcu_w));
  uint32_t min_h = (mcu_h<(max_y % mcu_h)?mcu_h:(max_y % mcu_h));

  // save the current image block size
  uint32_t win_w = mcu_w;
  uint32_t win_h = mcu_h;

  // save the coordinate of the right and bottom edges to assist image cropping
  // to the screen size
  max_x += xpos;
  max_y += ypos;

  // Fetch data from the file, decode and display
  while (JpegDec.read()) {    // While there is more data in the file
    pImg = JpegDec.pImage ;   // Decode a MCU (Minimum Coding Unit, typically a 8x8 or 16x16 pixel block)

    // Calculate coordinates of top left corner of current MCU
    int mcu_x = JpegDec.MCUx * mcu_w + xpos;
    int mcu_y = JpegDec.MCUy * mcu_h + ypos;

    // check if the image block size needs to be changed for the right edge
    if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
    else win_w = min_w;

    // check if the image block size needs to be changed for the bottom edge
    if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
    else win_h = min_h;

    // copy pixels into a contiguous block
    if (win_w != mcu_w)
    {
      uint16_t *cImg;
      int p = 0;
      cImg = pImg + win_w;
      for (int h = 1; h < win_h; h++)
      {
        p += mcu_w;
        for (int w = 0; w < win_w; w++)
        {
          *cImg = *(pImg + w + p);
          cImg++;
        }
      }
    }

    // calculate how many pixels must be drawn
    uint32_t mcu_pixels = win_w * win_h;

    // draw image MCU block only if it will fit on the screen
    if (( mcu_x + win_w ) <= tft.width() && ( mcu_y + win_h ) <= tft.height())
      tft.pushImage(mcu_x, mcu_y, win_w, win_h, pImg);
    else if ( (mcu_y + win_h) >= tft.height())
      JpegDec.abort(); // Image has run off bottom of screen so abort decoding
  }

  tft.setSwapBytes(swapBytes);

  showTime(millis() - drawTime); //將圖片顯示到屏幕所用的時(shí)間(ms)
}

void jpegInfo() {
  DebugPrintln("JPEG image info");
  DebugPrintln("===============");
  DebugPrint("Width      :");
  DebugPrintln(JpegDec.width);
  DebugPrint("Height     :");
  DebugPrintln(JpegDec.height);
  DebugPrint("Components :");
  DebugPrintln(JpegDec.comps);
  DebugPrint("MCU / row  :");
  DebugPrintln(JpegDec.MCUSPerRow);
  DebugPrint("MCU / col  :");
  DebugPrintln(JpegDec.MCUSPerCol);
  DebugPrint("Scan type  :");
  DebugPrintln(JpegDec.scanType);
  DebugPrint("MCU width  :");
  DebugPrintln(JpegDec.MCUWidth);
  DebugPrint("MCU height :");
  DebugPrintln(JpegDec.MCUHeight);
  DebugPrintln("===============");
  DebugPrintln("");
}

void showTime(uint32_t msTime) {
  DebugPrint(F(" JPEG drawn in "));
  DebugPrint(msTime);
  DebugPrintln(F(" ms "));
}

void SD_read_Time(uint32_t msTime) {
  Serial.print(F(" SD JPEG read in "));
  Serial.print(msTime);
  Serial.println(F(" ms "));
}
//程序結(jié)束,可以看這篇博客,我借鑒這位大佬的https://blog.csdn.net/weixin_42880082/article/details/125939534
回復(fù)

使用道具 舉報(bào)

34#
ID:891089 發(fā)表于 2023-2-24 22:37 來(lái)自觸屏版 | 只看該作者
美琴的備胎 發(fā)表于 2023-2-24 19:34
問(wèn)題解決了,用TFT_espi庫(kù),源程序放下面:
//程序開(kāi)始
/*

此貼完結(jié),謝謝大家
回復(fù)

使用道具 舉報(bào)

35#
ID:88256 發(fā)表于 2023-2-25 00:09 | 只看該作者
有始有終,值得一贊,不過(guò)用Arduino_GFX_Library庫(kù)不能用的問(wèn)題還是沒(méi)有解決,希望到時(shí)候有更完美的結(jié)果。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表