ESP32学习,驱动LED点阵屏,显示GIF动图

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提供了大量能使我们快速便捷地处理数据的函数和方法。

  • 18
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值