参考网址:
一个例子:
支持厂商-微雪
器件:
- arduino
- 转接板 (可要可不要)
- 墨水屏幕
墨水屏
https://detail.tmall.com/item.htm?spm=a1z0d.6639537/tb.1997196601.4.77f77484JaGssj&id=606230202834
代码
// by LingShunLAB.com
// refer:GxEPD2 library
#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h> // 加载 两色屏幕 GxEPD2 库
#include <Adafruit_GFX.h> // 加载 Adafruit_GFX 库
// 注意,以下定义适配 微雪2.9寸三色(黑白红)电子墨水屏在 Arduino Uno 使用
// 更多其他开发板,电子墨水屏的定义请查看GxEPD2库的例子
#define MAX_DISPLAY_BUFFER_SIZE 800
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
GxEPD2_BW<GxEPD2_290_T94_V2, MAX_HEIGHT(GxEPD2_290_T94_V2)> display(GxEPD2_290_T94_V2(/*CS=*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
// Include fonts from Adafruit_GFX
#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeMono12pt7b.h>
#include <Fonts/FreeMono18pt7b.h>
#include <Fonts/FreeMono24pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>
// 图像logo_1 取模数据
// 大小:300 x 86 像素
// 复制取模数据后,需要添加 PROGMEM 修饰符,表示变量存储在闪存
const unsigned char gImage_2[1806] PROGMEM = { /*0X00,0X01,0X78,0X00,0X78,0X00,*/
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XC7,0X1F,0XE0,
0X71,0XC7,0XE0,0X7E,0X7E,0X07,0XFF,0XFF,0XC0,0X07,0XFF,0XFF,0XC7,0X1F,0XE0,0X71,
0XC7,0XE0,0X7E,0X7E,0X07,0XFF,0XFF,0XC0,0X07,0XFF,0XFF,0XC7,0X1F,0XE0,0X71,0XC7,
0XE0,0X7E,0X7E,0X07,0XFF,0XFF,0XC0,0X07,0X00,0X01,0XC0,0XFC,0XFC,0X70,0X00,0X03,
0XFE,0X0F,0XC7,0X00,0X01,0XC0,0X07,0X00,0X01,0XC0,0XFC,0X7C,0X70,0X00,0X03,0XFE,
0X0F,0XC7,0X00,0X01,0XC0,0X07,0X00,0X01,0XC0,0XFC,0XFC,0X70,0X00,0X03,0XFE,0X0F,
0XC7,0X00,0X01,0XC0,0X07,0X1F,0XF1,0XC0,0X03,0XE0,0X00,0X38,0X1F,0X80,0X0F,0XC7,
0X1F,0XF1,0XC0,0X07,0X1F,0XF1,0XC0,0X03,0XE0,0X00,0X38,0X1F,0X80,0X0F,0XC7,0X1F,
0XF1,0XC0,0X07,0X1F,0XF1,0XC0,0X03,0XE0,0X00,0X38,0X1F,0X80,0X0F,0XC7,0X1F,0XF1,
0XC0,0X07,0X1F,0XF1,0XC7,0XFF,0XE0,0X7E,0X07,0X1F,0X80,0X0E,0X07,0X1F,0XF1,0XC0,
0X07,0X1F,0XF1,0XC7,0XFF,0XE0,0X7E,0X07,0X1F,0X80,0X0E,0X07,0X1F,0XF1,0XC0,0X07,
0X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E3,0XF8,0X3F,0X01,0XF8,0X31,0X81,0XFF,0X1F,
0XFF,0XC0,0X07,0X03,0X80,0X07,0XE3,0XE0,0X00,0X00,0X00,0X33,0X81,0XF8,0XFC,0X0E,
0X00,0X07,0X03,0X80,0X07,0XE3,0XE0,0X00,0X00,0X00,0X33,0X81,0XF8,0XFC,0X0E,0X00,
0X07,0X03,0X80,0X07,0XE3,0XE0,0X00,0XFE,0X00,0X33,0X81,0XF8,0XFC,0X0E,0X00,0X07,
0XFF,0XFF,0XFF,0X1C,0X60,0X00,0XDE,0X00,0X3F,0X8F,0XFF,0XE0,0X0E,0X00,0X07,0XFF,
0XFF,0XFF,0X1C,0XE0,0X00,0XBE,0X00,0X3F,0X8F,0XFF,0XE0,0X0E,0X00,0X07,0XFF,0XFF,
0XFF,0X1C,0XF0,0X00,0XBE,0X00,0X3F,0X8F,0XFF,0XE0,0X0E,0X00,0X07,0XFC,0X70,0X07,
0XE0,0XF8,0X00,0XFE,0X00,0X31,0X80,0X38,0X03,0XF1,0XC0,0X07,0XFC,0X70,0X07,0XE0,
0XF8,0X00,0XFE,0X00,0X31,0X80,0X38,0X03,0XF1,0XC0,0X07,0XFC,0X70,0X07,0XE0,0XF8,
0X00,0XFE,0X04,0X33,0X80,0X38,0X03,0XF1,0XC0,0X07,0XFF,0X8F,0XF8,0XFC,0XE0,0X1F,
0XFF,0XF0,0X3F,0X81,0XC7,0X1C,0X01,0XC0,0X07,0XFF,0X8F,0XF8,0XFC,0XE0,0X00,0X7F,
0X80,0X7F,0X81,0XC7,0X1C,0X01,0XC0,0X07,0XFF,0X8F,0XF8,0XFC,0XE0,0X00,0X00,0X00,
0X7F,0XC1,0XC7,0X1C,0X01,0X80,0X07,0XFC,0X7E,0X00,0X1F,0X83,0X00,0X00,0X00,0X01,
0XF0,0X00,0X03,0X8E,0X00,0X07,0XFC,0X7E,0X00,0X1F,0X03,0X80,0X38,0XFC,0X03,0XF0,
0X00,0X03,0X8E,0X00,0X07,0XFC,0X7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XC0,0X03,0X83,0X81,0XC7,0X1C,
0X0E,0X0E,0X38,0X03,0X8F,0XC0,0X07,0X1F,0XF1,0XC7,0XE0,0XE0,0X70,0X07,0X1C,0X03,
0XF0,0X38,0XFF,0X81,0XC0,0X07,0X1F,0XF1,0XC7,0XE0,0XE0,0X70,0X07,0X1C,0X01,0XF0,
0X38,0XFF,0X81,0XC0,0X07,0X1F,0XF1,0XC7,0XE0,0XE0,0X70,0X07,0X1C,0X03,0XF0,0X38,
0XFF,0X81,0XC0,0X07,0X00,0X01,0XC0,0X00,0X1C,0X70,0X00,0X1F,0X8F,0X8F,0XC0,0XFC,
0X0E,0X00,0X07,0X00,0X01,0XC0,0X00,0X1C,0X70,0X00,0X1F,0X8F,0X8F,0XC0,0XFC,0X0E,
0X00,0X07,0X00,0X01,0XC0,0X00,0X1C,0X70,0X00,0X1F,0X8F,0X8F,0XC0,0XFC,0X0E,0X00,
0X07,0XFF,0XFF,0XC0,0XE3,0XFC,0X7F,0XC0,0XE3,0XF3,0X81,0XC7,0XFC,0X0F,0XC0,0X07,
0XFF,0XFF,0XC0,0XE3,0XFC,0X7F,0XC0,0XE3,0XF1,0X81,0XC7,0XFC,0X0F,0XC0,0X07,0XFF,
0XFF,0XC0,0XE3,0XFC,0X7F,0XC0,0XE3,0XE1,0X81,0XC7,0XFC,0X0F,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,};
void setup() {
display.init(115200); // 初始化屏幕
display.setRotation(1); // 设置屏幕旋转方向,分别有0,1,2,3这四个方向
display.setTextWrap(false); // 设置文本是否自动换行,false则为不自动换行,如果文本溢出则显示异常或者不显示
const char HelloWorld[] = "XiaoHuTongXue"; //
display.setFont(&FreeMonoBold9pt7b); // 设置 文本字体
display.setTextColor(GxEPD_BLACK); // 设置 文本颜色
int16_t tbx, tby; // 文本框的x,y坐标
uint16_t tbw, tbh; // 文本框的宽度,高度
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh); // 计算渲染后的文本框的长度和宽度,用于居中
uint16_t x = ((display.width() - tbw) / 2) - tbx; // 文本框的x坐标
uint16_t y = ((display.height() - tbh) / 2) - tby; // 文本框的y坐标
display.setFullWindow();
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE); // 清屏(全平白色)
// (POSITION_X, POSITION_Y, IMAGE_NAME, IMAGE_WIDTH, IMAGE_HEIGHT, COLOR)
display.drawBitmap(0, 0, gImage_2, 120, 120, GxEPD_BLACK); // 在屏幕坐标(0,0)的位置显示 logo_1,大小为宽300,高86像素,颜色为黑色
// display.drawBitmap(0,0, gImage_logo_2, 300,86, display.epd2.hasColor ? GxEPD_WHITE : GxEPD_BLACK); // 在屏幕坐标(0,0)的位置显示 logo_1,大小为宽300,高86像素,颜色为红色
display.setCursor(x+50, y-30); // 设置指针位置
display.print("XiaoHuTongXue"); // 显示文本
display.setCursor(x+50, y);
display.print("LaoTie!");
display.setCursor(x+50, y+30);
display.print("Double 666 !!!");
}
while (display.nextPage());
}
void loop() {
}