ESP32学习,驱动LED点阵屏,显示GIF动图
研究了好多代码,小白也多少弄明白了,照搬呗。
循环显示的GIF动图拍下来的。
文章目录
前言
网上找了好久,无奈小白看不懂,测试了好多遍,终于成功了。
一、pandas是什么?
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。
二、使用步骤
1.主程序代码 vs代码
main.cpp(示例):
#include <Arduino.h>
#include "homer_tiny.h"
#include "gif_demo1.h"
#include "image4.h"
#include "image3g.h"
#include "image5.h"
#include <AnimatedGIF.h>
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
// This is the library for interfacing with the display
#include <U8g2_for_Adafruit_GFX.h>
// -------------------------------------
// ------- Matrix Config ------
// -------------------------------------
const int panelResX = 64; // Number of pixels wide of each INDIVIDUAL panel module.
const int panelResY = 64; // Number of pixels tall of each INDIVIDUAL panel module.
const int panel_chain = 2; // Total number of panels chained one to another
MatrixPanel_I2S_DMA *dma_display = nullptr;
AnimatedGIF gif;
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
void GIFDraw(GIFDRAW *pDraw)
{
uint8_t *s;
uint16_t *d, *usPalette, usTemp[320];
int x, y, iWidth;
usPalette = pDraw->pPalette;
y = pDraw->iY + pDraw->y; // current line
s = pDraw->pPixels;
if (pDraw->ucDisposalMethod == 2) // restore to background color
{
for (x = 0; x < iWidth; x++)
{
if (s[x] == pDraw->ucTransparent)
s[x] = pDraw->ucBackground;
}
pDraw->ucHasTransparency = 0;
}
if (pDraw->ucHasTransparency) // if transparency used
{
uint8_t *pEnd, c, ucTransparent = pDraw->ucTransparent;
int x, iCount;
pEnd = s + pDraw->iWidth;
x = 0;
iCount = 0; // count non-transparent pixels
while (x < pDraw->iWidth)
{
c = ucTransparent - 1;
d = usTemp;
while (c != ucTransparent && s < pEnd)
{
c = *s++;
if (c == ucTransparent) // done, stop
{
s--; // back up to treat it like transparent
}
else // opaque
{
*d++ = usPalette[c];
iCount++;
}
} // while looking for opaque pixels
if (iCount) // any opaque pixels?
{
for (int xOffset = 0; xOffset < iCount; xOffset++)
{
dma_display->drawPixel(x + xOffset, y, usTemp[xOffset]);
}
x += iCount;
iCount = 0;
}
// no, look for a run of transparent pixels
c = ucTransparent;
while (c == ucTransparent && s < pEnd)
{
c = *s++;
if (c == ucTransparent)
iCount++;
else
s--;
}
if (iCount)
{
x += iCount; // skip these
iCount = 0;
}
}
}
else
{
s = pDraw->pPixels;
for (x = 0; x < pDraw->iWidth; x++)
{
dma_display->drawPixel(x, y, usPalette[*s++]);
}
}
} /* GIFDraw() */
void displaySetup()
{
HUB75_I2S_CFG mxconfig(
panelResX, // module width
panelResY, // module height
panel_chain // Chain length
);
mxconfig.gpio.e = 32;
mxconfig.clkphase = false;
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->begin();
}
void setup()
{
Serial.begin(115200);
displaySetup();
dma_display->fillScreen(dma_display->color565(0, 0, 0));
dma_display->setBrightness8(20);
gif.begin(LITTLE_ENDIAN_PIXELS);
u8g2Fonts.begin(*dma_display);
u8g2Fonts.setFontMode(1);
u8g2Fonts.setFontDirection(0);
u8g2Fonts.setFont(u8g2_font_wqy12_t_gb2312);
int s= u8g2Fonts.getUTF8Width("人代会");
u8g2Fonts.setForegroundColor(dma_display->color565(255, random(100), random(100)));
u8g2Fonts.drawUTF8(80,61,"木林森");
}
void loop()
{
String str_="";
// put your main code here, to run repeatedly:
if (gif.open((uint8_t *)image4, sizeof(image4), GIFDraw))
{
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight());
while (gif.playFrame(true, NULL))
{
}
gif.close();
}
delay(2000);
dma_display->fillScreen(dma_display->color565(0, 0, 0));
str_="first image...";
u8g2Fonts.drawUTF8(80,61,str_.c_str());
delay(1000);
if (gif.open((uint8_t *)image3g, sizeof(image3g), GIFDraw))
{
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight());
while (gif.playFrame(true, NULL))
{
}
gif.close();
}
delay(2000);
dma_display->fillScreen(dma_display->color565(0, 0, 0));
str_="second image...";
u8g2Fonts.drawUTF8(80,61,str_.c_str());
delay(1000);
if (gif.open((uint8_t *)image5, sizeof(image5), GIFDraw))
{
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight());
while (gif.playFrame(true, NULL))
{
}
gif.close();
}
delay(2000);
dma_display->fillScreen(dma_display->color565(0, 0, 0));
str_="third image...";
u8g2Fonts.drawUTF8(80,61,str_.c_str());
delay(1000);
if (gif.open((uint8_t *)homer_tiny, sizeof(homer_tiny), GIFDraw))
{
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight());
while (gif.playFrame(true, NULL))
{
}
gif.close();
}
delay(2000);
dma_display->fillScreen(dma_display->color565(0, 0, 0));
if (gif.open((uint8_t *)gif_demo1, sizeof(gif_demo1), GIFDraw))
{
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight());
while (gif.playFrame(true, NULL))
{
}
gif.close();
}
delay(3000);
}
2.使用GIF工具制作动图
3.使用img_to_c转换 *.h 文件
使用语法很简单
成功
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
标签:dma,LED,gif,ESP32,GIF,pDraw,iCount,display From: https://blog.csdn.net/u011625956/article/details/136907400