【教程】(二)TFT_eSPI库之相关API

2 篇文章 0 订阅
2 篇文章 0 订阅

一、初始化相关API

1.初始化
tft.init();

初始化屏幕

2. 填充全屏幕
tft.fillScreen(uint32_t color);

填充全屏幕, 后面是颜色值

3.设置屏幕方向
tft.setRotation(1);

0为0°,1为90°,2为180°,3为270°

4. 颜色反转
tft.invertDisplay(bool i);

反转显示颜色i = 1反转,i = 0正常

二、文字相关API

1. 设置文字坐标位置和字号
 // 设置文本显示坐标,默认以文本左上角为参考点,可以改变参考点
tft.setCursor(int16_t x, int16_t y);
// 设置文本显示坐标,和文本的字体。特别注意: 字库7是仿7段数码屏的样式
tft.setCursor(int16_t x, int16_t y, uint8_t font); 
2. 设置字体颜色
// 设置文本颜色
tft.setTextColor(uint16_t color);
// 设置文本颜色与背景色
tft.setTextColor(uint16_t fgcolor, uint16_t bgcolor);
3. 设置字体大小
// 设置文本大小,文本大小范围为 1~7 的整数
tft.setTextSize(uint8_t size);
4. 显示字符串
tft.print("Hello World!");
tft.println("Hello World!");

三、绘制文字相关API

1. 绘制字符串(居左)
tft.drawString(const String &string, int32_t x, int32_t y);
tft.drawString(const char *string, int32_t x, int32_t y);
tft.drawString(const String &string, int32_t x, int32_t y, uint8_t font);
tft.drawString(const char *string, int32_t x, int32_t y, uint8_t font);

X坐标位于字符串的左边

2. 绘制字符串(居中)
tft.drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font);
tft.drawCentreString(const String &string, int32_t x, int32_t y, uint8_t font);

X坐标位于字符串的中间

3. 绘制字符串(居右)
tft.drawRightString(const char *string, int32_t x, int32_t y, uint8_t font);
tft.drawRightString(const String &string, int32_t x, int32_t y, uint8_t font);

X坐标位于字符串的右边

4. 绘制字符
tft.drawChar(uint16_t uniCode, int32_t x, int32_t y);
tft.drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font);
tft.drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size);
5. 绘制浮点数
tft.drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y);
tft.drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y, uint8_t font);
// 示例
tft.drawFloat(3.124, 4, 0,0,4)
6. 绘制数字
tft.drawNumber(long intNumber, int32_t x, int32_t y);
tft.drawNumber(long intNumber, int32_t x, int32_t y, uint8_t font);

四、 绘制几何图形

1. 点
tft.drawPixel(int32_t x, int32_t y, uint32_t color);
2.线
tft.drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint32_t color); //线段
tft.drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color); //横线(快速)
tft.drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color); //竖线(快速)
3. 圆
tft.drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color); //空心圆
tft.fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color); //实心圆
4. 椭圆
tft.drawEllipse(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color); //空心椭圆
tft.fillEllipse(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color); //实心椭圆
5. 矩形
tft.drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color); //空心矩形
tft.fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color); //实心矩形
6. 圆角矩形
tft.drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color); //空心圆角矩形
tft.fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color); //实心圆角矩形
7. 三角形
tft.drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color); //空心三角形
tft.fillTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color); //实心三角形

五、图片显示

1. BMP图片
tft.drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor);
tft.drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor);
2. XBM图片
tft.drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor);
tft.drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor);
3. 显示图片
tft.pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data);
tft.pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data);
tft.pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent);
tft.pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transparent)
tft.pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8 = true, uint16_t *cmap = (uint16_t *)nullptr);
tft.pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, uint8_t transparent, bool bpp8 = true, uint16_t *cmap = (uint16_t *)nullptr);
  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大宁帝国-KingChan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值