用Arduino玩ESP32(02):TFT_eSPI 库和液晶屏

TFT_eSPI常用函数及部分定义数据

#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT

********************************* 默认值 ********************************
rotation  = 0;
cursor_y  = cursor_x  = 0;
textfont  = 1;
textsize  = 1;
textcolor   = bitmap_fg = 0xFFFF; // White
textbgcolor = bitmap_bg = 0x0000; // Black
padX = 0;             // No padding
isDigits   = false;   // No bounding box adjustment
textwrapX  = true;    // Wrap text at end of line when using print stream
textwrapY  = false;   // Wrap text at bottom of screen when using print stream
textdatum = TL_DATUM; // Top Left text alignment is default
fontsloaded = 0;
***********************************************************************

begin(uint8_t tc) //Included for backwards compatibility
init(uint8_t tc) //Reset, then initialise the TFT display registers

setRotation(uint8_t m) //rotate the screen orientation m = 0-3 or 4-7 for BMP drawing
旋转屏幕,m=0-3或4-7 0 = 0,1 = 90,2 = 180,3 = 270。

writecommand(uint8_t c) //Send an 8 bit command to the TFT examples/320 x 240/TFTwidth(_Matrix/TFT_Matrix.ino
writedata(uint8_t d) //Send a 8 bit data value to the TFT
readcommand8(uint8_t cmd_function, uint8_t index) //Read a 8 bit data value from an indexed command register
readcommand16(uint8_t cmd_function, uint8_t index) //Read a 16 bit data value from an indexed command register
readcommand32(uint8_t cmd_function, uint8_t index) //Read a 32 bit data value from an indexed command register

readPixel(int32_t x0, int32_t y0) //Read 565 pixel colours from a pixel

setCallback(getColorCallback getCol)

readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) //Read 565 pixel colours from a defined area

pushRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) //push 565 pixel colours into a defined area

pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) //plot 16 bit colour sprite or image onto TFT
pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transp) //plot 16 bit sprite or image with 1 colour being transparent
pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) //plot 16 bit image
pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transp) //plot 16 bit image with 1 colour being transparent
pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8) //plot 8 bit image or sprite using a line buffer
pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, uint8_t transp, bool bpp8) //plot 8 or 1 bit image or sprite with a transparent colour

setSwapBytes(bool swap) //Used by 16 bit pushImage() to swap byte order in colours
getSwapBytes(void)  //Return the swap byte order for colours

readRectRGB(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_t *data) //Read RGB pixel colours from a defined area




****************************  圆  ***********************************
drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color),
在x和y位置使用r和color,绘制一个圆

fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color),
在x和y位置使用r和t color中绘制一个实心圆。

/*drawCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, uint32_t color),
在x和y位置使用r和color,绘制一个缺口为cornername度的圆
fillCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, int32_t delta, uint32_t color),
在x和y位置使用r radius和t color中绘制一个cornername度的实心扇形?
*/作用未知

drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color),
画椭圆
fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color),
填充椭圆
*****************************************************************************


***************************** 矩形 ***********************************
drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color),
在x和y位置绘制一个填充的矩形。 w是宽度,h是高度,t是rextangle的颜色

drawRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color),
绘制一个圆角矩形,在x和y位置具有r半径圆角,w宽度和h高度和t颜色

fillRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color),
绘制一个填充的圆角矩形,其中x和y位置具有r半径圆角,w宽度和h高度和t颜色
*********************************************************************

fillScreen(uint32_t color)
将液晶屏颜色更改为color颜色。 color应该是包含UTFT颜色代码的32位变量

******************************** 三角形 **************************************
drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color),
绘制一个三角形位置x、y和z以及color颜色的三角形

fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color),
绘制一个三角形位置x、y和z以及color颜色的填充三角形
******************************************************************************

******************************** 显示单色图像 **************************************
drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color),
首先,您应该将图像转换为十六进制代码。如果您不想更改软件的设置,则必须反转图像的颜色并使图像水平镜像并逆时针旋转90度。现在将其添加到软件并进行转换。打开导出的文件并将十六进制代码复制到Arduino IDE。 x和y是图像的位置。 w和h是图像的大小。您可以在最后一个输入中更改图像的颜色。

drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color),
xbm是一种简单的双色图片位图格式,在早期的cgi中运用较多,目前多用于计数器上
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor),
有前景、背景色
***********************************************************************************

*********************************** 光标,文本、图像设置 ****************************************
setCursor(int16_t x, int16_t y)
将光标位置设置为x和y
setCursor(int16_t x, int16_t y, uint8_t font)
将光标位置设置为x和y,字体为font

getCursorX(void)
getCursorY(void)
获取光标位置,X,Y

setTextSize(uint8_t s)
设置文本大小,S是1-7之间的数字
setTextColor(uint16_t c)
设置文本的颜色
setTextColor(uint16_t c, uint16_t b)
设置文本的颜色及其背景

setPivot(int16_t x, int16_t y)
getPivotX(void)
getPivotY(void)

setBitmapColor(uint16_t fgcolor, uint16_t bgcolor), // For 1bpp sprites
设置图像前后颜色

setTextWrap(boolean wrapX, boolean wrapY)
设置文本是否换行

setTextDatum(uint8_t d)
设置文本基准
setTextPadding(uint16_t x_width)
设置填充宽度,擦除原来的文字和数字

getRotation(void)
获取数字m
getTextDatum(void)
获取文本基准

width(void) //Return the pixel width of display (per current rotation)
height(void) //Return the pixel height of display (per current rotation)

textWidth(const String& string)
返回 字符串在当前字体下的像素宽度
textWidth(const String& string, uint8_t font)
返回 字符串在字体font下的像素宽度

fontsLoaded(void) //return an encoded 16 bit value showing the fonts loaded

fontHeight(int16_t font) //return the height of a font (yAdvance for free fonts)
fontHeight(void)

*************************************** 显示文本、数字 *****************
setAddrWindow(int32_t x0, int32_t y0, int32_t w, int32_t h) //define an area to receive a stream of pixels

drawPixel(int32_t x, int32_t y, uint32_t color) //push a single pixel at an arbitrary position

pushColor(uint16_t color) //push a single pixel
pushColor(uint16_t color, uint32_t len) //push a single colour to "len" pixels

startWrite(void) //begin transaction with CS low, MUST later call endWrite
endWrite(void) //end transaction with CS high

pushColors(uint8_t *data, uint32_t len) //push an array of pixels for 16 bit raw image drawing(Assumed that setAddrWindow() has previously been called)
pushColors(uint16_t *data, uint32_t len, bool swap) //push an array of pixels, for image drawing
----------------------------------------------------------------------

drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color) //draw a line between 2 arbitrary points

drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color) //draw a vertical line
drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color) //draw a horizontal line

fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)//draw a filled rectangle

color565(uint8_t r, uint8_t g, uint8_t b) //convert three 8 bit RGB levels to a 16 bit colour value
color16to8(uint16_t c) //convert 16 bit colour to an 8 bit 332 RGB colour value
color8to16(uint8_t color) //convert 8 bit colour to a 16 bit 565 colour value

invertDisplay(boolean i) //invert the display colours i = 1 invert, i = 0 normal 反转屏幕的颜色

decodeUTF8(uint8_t c) //Serial UTF-8 decoder with fall-back to extended ASCII
decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining) //Line buffer UTF-8 decoder with fall-back to extended ASCII

drawChar(uint16_t uniCode, int32_t x, int32_t y)//draw a single character in the Adafruit GLCD font(Any UTF-8 decoding must be done before calling drawChar())
drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font)

// Without font number, uses font set by setTextFont()
drawString(const String& string, int32_t poX, int32_t poY)
// With font number
drawString(const String& string, int32_t poX, int32_t poY, uint8_t font)
// Without font number, uses font set by setTextFont()
drawString(const char *string, int32_t poX, int32_t poY)
// With font number. Note: font number is over-ridden if a smooth font is loaded
drawString(const char *string, int32_t poX, int32_t poY, uint8_t font)

//draw string centred on dX
drawCentreString(const String& string, int32_t dX, int32_t poY, uint8_t font)
drawCentreString(const char *string, int32_t dX, int32_t poY, uint8_t font)
//draw string right justified to dX
drawRightString(const String& string, int32_t dX, int32_t poY, uint8_t font)
drawRightString(const char *string, int32_t dX, int32_t poY, uint8_t font)

drawNumber(long long_num, int32_t poX, int32_t poY) //draw a long integer
drawNumber(long long_num, int32_t poX, int32_t poY, uint8_t font)

drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY) //drawFloat, prints 7 non zero digits maximum
drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY, uint8_t font)
*************************************************************************************

setFreeFont(const GFXfont *f) //Sets the GFX free font to use
setTextFont(uint8_t f) //Set the font for the print stream
setFreeFont(uint8_t font) //Sets the GFX free font to use

getSetup(setup_t &tft_settings) //Get the setup details for diagnostic and sketch access

液晶屏引脚

RST   液晶屏复位控制引脚(低电平复位)
CS    液晶屏选控制引脚(低电平使能,不做SPI复用片选时,接地,省1个IO口)
D/C   数据/命令选择控制引脚(高电平:数据,低电平:命令)
DIN   SPI总线写数据引脚
CLK   SPI总线时钟引脚
VCC   电源正极引脚 5V
BL    背光控制引脚(高电平点亮,如不需控制,直接接3.3V)
GND   电源地引脚

User_Setup.h 引脚设定

没有ESP32专门的ST7735驱动引脚设定,可以用ESP8266的,
源文件96行开始
// Typical setup for ESP8266 NodeMCU ESP-12 is :
//
// Display SDO/MISO  to NodeMCU pin D6 (or leave disconnected if not reading TFT)
// Display LED       to NodeMCU pin VIN (or 5V, see below)---BL
// Display SCK       to NodeMCU pin D5  ---CLK
// Display SDI/MOSI  to NodeMCU pin D7 --- DIN
// Display DC (RS/AO)to NodeMCU pin D3 ---D/C
// Display RESET     to NodeMCU pin D4 (or RST, see below)
// Display CS        to NodeMCU pin D8 (or GND, see below)
// Display GND       to NodeMCU pin GND (0V)
// Display VCC       to NodeMCU 5V or 3.3V
//
// The TFT RESET pin can be connected to the NodeMCU RST pin or 3.3V to free up a control pin. 
//
再从125行开始看,省掉几个IO口设置后,只需设置DC一个IO口。MOSI 23 SCLK 18,这两个引脚是必须插上的,可以不用在代码里定义
// ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP8266 SETUP ######

// For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation
//#define TFT_CS   PIN_D8  // Chip select control pin D8 接3.3V,省一个IO口
#define TFT_DC   27  // Data Command control pin
//#define TFT_RST  PIN_D4  // Reset pin (could connect to NodeMCU RST, see next line)
#define TFT_RST  -1    // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,530评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,403评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,120评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,770评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,758评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,649评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,021评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,675评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,931评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,751评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,410评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,004评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,969评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,042评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,493评论 2 343

推荐阅读更多精彩内容