|
tft.startWrite()是TFT_eSPI庫(已使用)中的代碼但報(bào)錯(cuò)是exit status 1 class Adafruit_ST7735' has no member named 'startWrite'; did you mean 'spiwrite'?
感覺沒有掃描到我引用的TFT_eSPI,一直說Adafruit_ST7735中沒有tft.startWrite()
源代碼如下,求求各位大神幫幫孩子吧。
//接線方式https://blog.csdn.net/moshanghuaw/article/details/122037124
#include <TFT_eSPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SD.h>
#include <SPI.h>
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
//TFT顯示屏和SD卡將共享硬件SPI接口。
//硬件SPI引腳特定于Arduino板類型
//無法重新映射到備用接點(diǎn)。對于Arduino Uno,
//Duemilanove等,引腳11=MOSI,引腳12=MISO,引腳13=SCK。
#define SD_CS 4 // Chip select line for SD card
#define TFT_CS 10 // Chip select line for TFT display
#define TFT_DC 9 // Data/command line for TFT
#define TFT_RST 8 // Reset line for TFT (or connect to +5V)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define BUFFPIXEL 20
void bmpDraw(char *filename, uint8_t x, uint8_t y)
{
File bmpFile;
int bmpWidth, bmpHeight; // W+H(以像素為單位)
uint8_t bmpDepth; // 位深度(當(dāng)前必須為24)
uint32_t bmpImageoffset; // 文件中圖像數(shù)據(jù)的開始
uint32_t rowSize; // 不總是=bmpWidth;可能有填充
uint8_t sdbuffer[3*BUFFPIXEL]; // 像素緩沖區(qū)(每個(gè)像素R+G+B)
uint8_t buffidx = sizeof(sdbuffer); // sdbuffer中的當(dāng)前位置
boolean goodBmp = false; // 在有效的標(biāo)頭分析時(shí)設(shè)置為true
boolean flip = true; // BMP自下而上存儲
int w, h, row, col;
uint8_t r, g, b;
uint32_t pos = 0, startTime = millis();
if((x >= tft.width()) || (y >= tft.height())) return;
// 在SD卡上打開請求的文件
if ((bmpFile = SD.open(filename)) == NULL)
{
return;
}
// 分析BMP標(biāo)頭,二進(jìn)制BMP文件以0x4D42開頭
if(read16(bmpFile) == 0x4D42)
{ // BMP簽名
Serial.print("File size: ");
Serial.println(read32(bmpFile));
(void)read32(bmpFile); // 讀取并忽略創(chuàng)建者字節(jié)
bmpImageoffset = read32(bmpFile); // 圖像數(shù)據(jù)的開始
// 讀取DIB標(biāo)題
Serial.print("Header size: ");
Serial.println(read32(bmpFile));
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1)
{ // # planes -- must be '1'
bmpDepth = read16(bmpFile); // 每像素位
if((bmpDepth == 24) && (read32(bmpFile) == 0))
{ // 0 = uncompressed
goodBmp = true; // 支持的BMP格式--繼續(xù)!
// BMP行填充(如果需要)到4字節(jié)邊界
rowSize = (bmpWidth * 3 + 3) & ~3;
//若bmpHeight為負(fù)數(shù),則圖像按自上而下的順序排列。
//這不是標(biāo)準(zhǔn),而是在野外觀察到的。
if(bmpHeight < 0) {
bmpHeight = -bmpHeight;
flip = false;
}
// 要裝載的作物區(qū)域
w = bmpWidth;
h = bmpHeight;
if((x+w-1) >= tft.width()) w = tft.width() - x;
if((y+h-1) >= tft.height()) h = tft.height() - y;
// 將TFT地址窗口設(shè)置為剪切圖像邊界
tft.startWrite();
tft.setAddrWindow(x, y, w, h);
for (row=0; row<h; row++)
{ //對于每條掃描線。。。
//尋找掃描線的起點(diǎn)。這可能看起來很吃力
//每一行都要這么做,但這
//這種方法涵蓋了很多細(xì)節(jié),比如裁剪
//以及掃描線填充。此外,搜索只需要
//如果文件位置確實(shí)需要更改,則放置
//(避免了SD庫中的大量集群數(shù)學(xué))。
if(flip) // 位圖按自下而上的順序存儲(普通BMP)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
else // 位圖自上而下存儲
pos = bmpImageoffset + row * rowSize;
if(bmpFile.position() != pos) { // 需要尋求?
tft.endWrite();
bmpFile.seek(pos);
buffidx = sizeof(sdbuffer); // 強(qiáng)制重新加載緩沖區(qū)
}
for (col=0; col<w; col++)
{ // 對于每個(gè)像素。。。
// 是時(shí)候讀取更多像素?cái)?shù)據(jù)了嗎?
if (buffidx >= sizeof(sdbuffer)) { // 的確
bmpFile.read(sdbuffer, sizeof(sdbuffer));
buffidx = 0; // 將索引設(shè)置為開頭
tft.startWrite();
}
// 將像素從BMP轉(zhuǎn)換為TFT格式,按鍵顯示
r = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
b = sdbuffer[buffidx++];
tft.pushColor(tft.color565(r,g,b));
} // end pixel
} // end scanline
tft.endWrite();
} // end goodBmp
}
}
bmpFile.close();
if(!goodBmp) Serial.println("BMP format not recognized.");
}
//這些從SD卡文件中讀取16位和32位類型。
//BMP數(shù)據(jù)存儲為小端序,Arduino也是小端序。
//如果移植到其他地方,可能需要顛倒下標(biāo)順序。
uint16_t read16(File f) {
uint16_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); // MSB
return result;
}
uint32_t read32(File f) {
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
return result;
}
void setup(void) {
pinMode(12,INPUT); // 設(shè)置SD的MISO IO狀態(tài),非常重要!
Serial.begin(9600);
// Initialize 1.8" TFT
tft.initR(INITR_REDTAB); // (已解決)顯示部分圖像128X128,其余部分為花邊,復(fù)位斷電重連無用,圖片一側(cè)隨RX燈的閃動而變色,使用tft.initR(INITR_BLACKTAB)后顯示完整其余不變,復(fù)位后不變斷電重連后癥狀恢復(fù)
//tft.initR(INITR_HALLOWING); // 解決方法 在Adafuit_ST7735.h的第13行將INITR_144GRENTAB更改為0x03,例如#define INITR_14GRENTAB 0x03
//tft.initR(INITR_144GREENTAB); // 同上
//tft.initR(INITR_BLACKTAB); // 圖片全部顯示,色調(diào)不對,無閃動變色現(xiàn)象
tft.setRotation(3);
tft.fillScreen(ST7735_BLACK);
}
void loop() {
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS))
{
Serial.println("failed!");
tft.setTextSize(2);
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ST7735_BLUE);
tft.print("SD Card init error!");
return;
}
bmpDraw("x.bmp", 0, 0);
}
|
-
|