用arduino编程GxEPD2库墨水屏随机显示取模图片
以下是一个简单的示例程序,使用Arduino编程和GxEPD2库来随机显示取模图片。
#include <GxEPD2_BW.h> // include the GxEPD2 library
#include <SPI.h> // include the SPI library
// initialize the display
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT / 8> display(GxEPD2_154_D67(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
void setup() {
// initialize the SPI bus
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
// initialize the display
display.init(115200);
}
void loop() {
// list of bitmap images
static const unsigned char PROGMEM images[][32] = {
{0x3C,0x42,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x42,0x3C},
{0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x00,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x00},
{0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0xFF,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81},
{0x00,0x00,0x00,0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81},
{0x81,0xC3,0xC3,0xC3,0xA5,0xA5,0xFF,0xDB,0xDB,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3},
{0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3},
{0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81}
};
// randomly choose an image
int index = random(0, 8);
// clear the display
display.clear();
// draw the image
display.drawBitmap(0, 0, images[index], 16, 8, GxEPD_WHITE);
// refresh the display
display.display();
// wait for a few seconds
delay(5000);
}
该程序使用了GxEPD2_BW类,它是GxEPD2库中用于控制黑白墨水屏的类。在setup()函数中,我们初始化了SPI总线并初始化了显示屏。在loop()函数中,我们定义了一个包含8个不同图像的数组,然后使用random()函数随机选择一个图像。我们使用display.clear()清除屏幕,然后使用display.drawBitmap()函数绘制所选图像。最后,我们使用display.display()函数刷新屏幕并等待几秒钟,然后重复该过程。
原文地址: https://www.cveoy.top/t/topic/f2j 著作权归作者所有。请勿转载和采集!