ESP32点亮LCD屏

1.实现效果

ESP32点亮LCD屏

2.代码展示

// This example renders a png file that is stored in a FLASH array

// using the PNGdec library (available via library manager).

// this sketch is will not run on smaller memory processors (e.g.

// ESP8266, STM32F103 etc.)

// The example png is encoded as ARGB 8 bits per pixel with indexed colour

// It was created using GIMP and has a transparent background area.

// Image files can be converted to arrays using the tool here:

// https://notisrac.github.io/FileToCArray/

// To use this tool:

//   1. Drag and drop PNG image file on "Browse..." button

//   2. Tick box "Treat as binary"

//   3. Click "Convert"

//   4. Click "Save as file" and move the header file to sketch folder

//      (alternatively use the "Copy to clipboard" and paste into a new tab)

//   5. Open the sketch in IDE

//   6. Include the header file containing the array (SpongeBob.h in this example)

// Include the PNG decoder library, available via the IDE library manager

#include <PNGdec.h>

// Include image array

#include "SpongeBob.h"

PNG png; // PNG decoder instance

#define MAX_IMAGE_WIDTH 240 // Sets rendering line buffer lengths, adjust for your images

// Include the TFT library - see https://github.com/Bodmer/TFT_eSPI for library information

#include "SPI.h"

#include <TFT_eSPI.h>              // Hardware-specific library

TFT_eSPI tft = TFT_eSPI();         // Invoke custom library

// Position variables must be global (PNGdec does not handle position coordinates)

int16_t xpos = 0;

int16_t ypos = 0;

void setup()

{

  Serial.begin(115200);

  Serial.println("\n\n Using the PNGdec library");

  // Initialise the TFT

  tft.begin();

  tft.fillScreen(TFT_BLACK);

  Serial.println("\r\nInitialisation done.");

}

void loop()

{

  uint16_t pngw = 0, pngh = 0; // To store width and height of image

  int16_t rc = png.openFLASH((uint8_t *)bob, sizeof(bob), pngDraw);

  if (rc == PNG_SUCCESS) {

    Serial.println("Successfully opened png file");

    pngw = png.getWidth();

    pngh = png.getHeight();

    Serial.printf("Image metrics: (%d x %d), %d bpp, pixel type: %d\n", pngw, pngh, png.getBpp(), png.getPixelType());

    tft.startWrite();

    uint32_t dt = millis();

    rc = png.decode(NULL, 0);

    tft.endWrite();

    Serial.print(millis() - dt); Serial.println("ms");

    tft.endWrite();

  }

  delay(250);

  // Randomly change position

  xpos = random(tft.width() - pngw);

  ypos = random(tft.height() - pngh);

  // Fill screen with a random colour at random intervals

  if (random(100) < 20) tft.fillScreen(random(0x10000));

}

微信小程序搜 “涨知识1024”

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值