static const uint8_t name[] PROGMEM =
{ //Add image code here.
}
tft.drawBitmap(x, y, name, sx, sy, 0x0000);
首先你应将您的图像转换为十六进制代码。从以下链接下载该软件。如果您不想更改软件的设置,则必须反转图像的颜色并使图像水平镜像并逆时针旋转 90 度。现在将其添加到软件并进行转换。打开导出的文件并将十六进制代码复制到 Arduino IDE。 x 和 y 是图像的位置。 sx 和 sy 是图像的大小。您可以在最后一个输入中更改图像的颜色。
RGB 彩色图像显示
const uint16_t name[] PROGMEM = {
//Add image code here.
}
tft.drawRGBBitmap(x, y, name, sx, sy);
首先,您应该将图像转换为代码。使用此链接转换图像:
http://www.rinkydinkelectronics.com/t_imageconverter565.php
上传图像并下载 UTFT 库可以处理的转换文件。现在将十六进制代码复制到 Arduino IDE。 x 和 y 是图像的位置。 sx 和 sy 是图像的大小。
预先设计的模板
载入
在这个模板中,我们只使用了一个字符串和 8 个实心圆圈按顺序改变颜色。要在静态点周围绘制圆圈,可以使用 sin(); 和 cos(); 功能。您应该定义 PI 编号。要更改颜色,可以使用 color565(); 功能并替换您的 RGB 代码。
#include “Adafruit_GFX.h”
#include “MCUFRIEND_kbv.h”
MCUFRIEND_kbv tft;
#include “Fonts/FreeSans9pt7b.h”
#include “Fonts/FreeSans12pt7b.h”
#include “Fonts/FreeSerif12pt7b.h”
#include “FreeDefaultFonts.h”
#define PI 3.1415926535897932384626433832795
int col[8];
void showmsgXY(int x, int y, int sz, const GFXfont f, const char msg)
{
int16_t x1, y1;
uint16_t wid, ht;
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(0x0000);
tft.setTextSize(sz);
tft.print(msg);
}
void setup() {
tft.reset();
Serial.begin(9600);
uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(1);
tft.invertDisplay(true);
tft.fillScreen(0xffff);
showmsgXY(170, 250, 2, &FreeSans9pt7b, “Loading.。.”);
col[0] = tft.color565(155, 0, 50);
col[1] = tft.color565(170, 30, 80);
col[2] = tft.color565(195, 60, 110);
col[3] = tft.color565(215, 90, 140);
col[4] = tft.color565(230, 120, 170);
col[5] = tft.color565(250, 150, 200);
col[6] = tft.color565(255, 180, 220);
col[7] = tft.color565(255, 210, 240);
}
void loop() {
for (int i = 8; i 》 0; i--) {
tft.fillCircle(240 + 40 (cos(-i PI / 4)), 120 + 40 (sin(-i PI / 4)), 10, col[0]); delay(15);
tft.fillCircle(240 + 40 (cos(-(i + 1)PI / 4)), 120 + 40 (sin(-(i + 1)PI / 4)), 10, col[1]); delay(15);
tft.fillCircle(240 + 40 (cos(-(i + 2)PI / 4)), 120 + 40 (sin(-(i + 2)PI / 4)), 10, col[2]); delay(15);
tft.fillCircle(240 + 40 (cos(-(i + 3)PI / 4)), 120 + 40 (sin(-(i + 3)PI / 4)), 10, col[3]); delay(15);
tft.fillCircle(240 + 40 (cos(-(i + 4)PI / 4)), 120 + 40 (sin(-(i + 4)PI / 4)), 10, col[4]); delay(15);
tft.fillCircle(240 + 40 (cos(-(i + 5)PI / 4)), 120 + 40 (sin(-(i + 5)PI / 4)), 10, col[5]); delay(15);
tft.fillCircle(240 + 40 (cos(-(i + 6)PI / 4)), 120 + 40 (sin(-(i + 6)PI / 4)), 10, col[6]); delay(15);
tft.fillCircle(240 + 40 (cos(-(i + 7)PI / 4)), 120 + 40 (sin(-(i + 7)PI / 4)), 10, col[7]); delay(15);
}
}
徽标演示
在此模板中,我们将 a.jpg 图像转换为. c 文件并添加到代码中,写了一个字符串并使用淡入淡出代码进行显示。然后我们使用滚动代码向左移动屏幕。下载. h 文件并将其添加到 Arduino sketch 的文件夹中。
#include “Adafruit_GFX.h” // Core graphics library
#include “MCUFRIEND_kbv.h” // Hardware-specific library
MCUFRIEND_kbv tft;
#include “Ard_Logo.h”
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF
#define GREY 0x8410
#include “Fonts/FreeSans9pt7b.h”
#include “Fonts/FreeSans12pt7b.h”
#include “Fonts/FreeSerif12pt7b.h”
#include “FreeDefaultFonts.h”
void showmsgXY(int x, int y, int sz, const GFXfont f, const char msg)
{
int16_t x1, y1;
uint16_t wid, ht;
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextSize(sz);
tft.println(msg);
}
uint8_t r = 255, g = 255, b = 255;
uint16_t color;
void setup()
{
Serial.begin(9600);
uint16_t ID = tft.readID();
tft.begin(ID);
tft.invertDisplay(true);
tft.setRotation(1);
}
void loop(void)
{
tft.invertDisplay(true);
tft.fillScreen(WHITE);
tft.drawRGBBitmap(100, 50, Logo, 350, 200);
delay(1000);
tft.setTextSize(2);
for (int j = 0; j 《 20; j++) {
color = tft.color565(r -= 12, g -= 12, b -= 12);
tft.setTextColor(color);
showmsgXY(95, 280, 1, &FreeSans12pt7b, “ELECTROPEAK PRESENTS”);
delay(20);
}
delay(1000);
for (int i = 0; i 《 480; i++) {
tft.vertScroll(0, 480, i);
tft.drawFastVLine(i, 0, 320, 0xffff); // vertical line
delay(5);}
while (1);
}