|
库:Arduino IDE 库管理中搜索 TFT_eSPI。或者手动下载:https://github.com/Bodmer/TFT_eSPI
接线方法稍后再说。库装成功后转到 C:\Users\<用户>\Documents\Arduino\libraries\TFT_eSPI-master (路径仅供参考)
修改User_Setup.h,注释掉以下内容:
#define TFT_CS PIN_D8 // Chip select control pin D8
#define TFT_DC PIN_D3 // Data Command control pin
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
找到这句,并反注释以下#define:
// For ESP32 Dev board (only tested with ILI9341 display)
// The hardware SPI can be mapped to any pins
#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 15 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST 4 // Reset pin (could connect to RST pin)
看到这段话应该也明白了吧,它其实也是接线指南。
TFT屏的LED引脚可以串一个100欧姆左右的电阻后连接Vcc。(不确定电阻不接是否会伤屏)
代码扒自参考库自带的 Generic -> TFT_FLASH_BITMAP。
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#include "Close.h"
long count = 0; // Loop count
void setup()
{
tft.begin();
tft.setRotation(1); // landscape
tft.fillScreen(TFT_BLACK);
// Swap the colour byte order when rendering
tft.setSwapBytes(true);
// Draw the icons
//tft.pushImage(0, 0, infoWidth, infoHeight, info);
tft.pushImage(0,0,closeWidth,closeHeight,closeX);
// Pause here to admire the icons!
delay(2000);
}
图像代码直接在示例里的Close.h里改了,用图片取模工具生成C代码。(我用的是ImageConverter565)
#include <pgmspace.h>
// Icon width and height
const uint16_t closeWidth = 156;
const uint16_t closeHeight = 153;
const unsigned short closeX[0x5D3C] PROGMEM={
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFDF, // 0x0010 (16)
0xFFFF, 0xFFDF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFDF, 0xFFFF, 0xF79E, 0xFFFF, 0xFFDF, 0xFFFF, 0xFFFF, 0xFFDF, 0xF79E, // 0x0020 (32)
0xFFDF, 0xFFFF, 0xEF5D, 0xF79E, 0xFFFF, 0xF7BE, 0xFFDF, 0xFFFF, 0xFFFF, 0xFFFF, 0xF79E, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0030 (48)
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0040 (64)
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0050 (80)
.......
};
编译,烧录,,,
|
|