首页 > 其他分享 >ESP32学习,驱动LED点阵屏,显示GIF动图

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

时间:2024-03-22 21:31:04浏览次数:21  
标签:dma LED gif ESP32 GIF pDraw iCount display

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

相关文章

  • 解决出现javax.net.ssl.SSLHandshakeException: PKIX path building failed 或 sun.se
    From: https://www.cnblogs.com/luoxiao1104/p/16671501.html当我们从网络上根据url下载文件的时候可能会出现一下异常错误信息: javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:......
  • 基于51单片机智能停车场管理车位引导系统红外检测OLED设计21-295
    21-295、51单片机智能停车场管理车位引导系统红外检测OLED液晶汉字显示设计产品功能描述:本系统由STC89C52单片机、红外对管传感器、0.96寸OLED液晶屏、LED指示灯及电源组成。1、通过红外对管模块实时检测车位是否占用,车位分为1车位,2车位,3车位。2、液晶实时显示车位是否被占......
  • SpringbootLogingApplication has been compiled by a more recent version of the Ja
    一、问题描述:        SpringbootLogingApplicationhasbeencompiledbyamorerecentversionoftheJavaRuntime(classfileversion61.0),thisversionoftheJavaRuntimeonlyrecognizesclassfileversionsupto55.0        更新版本的Ja......
  • Java使用注解@Scheduled开启定时任务
    @Scheduled(cron="[秒][分][小时][日][月][周][年]")说明:多个并列的时间以英文逗号“,”隔开。比如:@Scheduled(cron="053,55161**")上面意思是:1号的下午16:53,16:55执行二次。 @Scheduled(cron="0/10****?")每隔10秒运行一次。 @Scheduled(c......
  • ESP32上传失败,ESP32: No serial data received,Failed uploading: uploading error: ex
    ESP32:Noserialdatareceived解决方案给ESP32烧录的时候,报错Afatalerroroccurred:FailedtoconnecttoESP32:Noserialdatareceived.Fortroubleshootingstepsvisit:https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.htmlFa......
  • ACCESS 关于使用VBA选择路径时提示"方法'FileDislog作用于对象'_Application’时失败"
    以下是源码:PrivateSubCommand0_Click()'打开文件选择对话框WithApplication.FileDialog(msoFileDialogFilePicker).AllowMultiSelect=False.Filters.Clear.Filters.Add"Excel文件","*.xls;*.xlsx",1I......
  • 【飞浆AI实战】交通灯检测:手把手带你入门PaddleDetection,从训练到部署
    前言本次分享将带领大家从0到1完成一个目标检测任务的模型训练评估和推理部署全流程,项目将采用以PaddleDetection为核心的飞浆深度学习框架进行开发,并总结开发过程中踩过的一些坑,希望能为有类似项目需求的同学提供一点帮助。项目背景和目标背景:目标检测是计算机视觉的一......
  • 【嵌入式学习笔记】---- OLED屏幕工作原理
    1驱动芯片SSD1603简介1.1SSD1603芯片图SSD1603是一款点阵显示屏控制器,可嵌入在屏幕中,用于执行接收数据、显示存储、扫描刷新等任务驱动接口:128个SEG引脚和64个COM引脚,对应\(128\times64\)像素点阵显示屏内置显示存储器(GDDRAM):\(128\times64Bit(或128\times64Byte)SRAM\)......
  • zabbix报错fping failed:no output
    zabbix的web前端界面突然连接不上了,页面一直转圈,无法响应,如下图: 排查思路如下:1、检查zabbix-server、Apache2、MySQL进程,发现都是active状态没有问题,端口号也正常2、查看zabbix-server日志文件,发现有报错,想着重启下zabbix-server进程,但是重启zabbix-server进程根本起不来,总......
  • JAVA线程池ScheduledThreadPool实践教程
    ScheduledThreadPool用于在给定的延迟之后,或者定期执行任务。以下是如何在Java中实践使用ScheduledThreadPool的步骤:步骤1:创建ScheduledThreadPool首先,使用Executors的newScheduledThreadPool方法来创建一个ScheduledThreadPool。参数是你想要在池中保持的线程数量。i......