利用TFT_eSPI库和ESP32实现类似黑客帝国(Matrix)的文字下落(与例程不同)

#include <TFT_eSPI.h>
#include <SPI.h>

'''Node MCU32S LCD ILI9341 240*320'''

TFT_eSPI tft = TFT_eSPI();
int startPoints[12];
uint16_t colors[5];
void setup() {
  tft.init();
  randomSeed(analogRead(A0));
  tft.fillScreen(TFT_BLACK);
  for(int i = 0;i<12;i++)
  {
    int randTemp = random(0,18);
    startPoints[i] = randTemp;
  }
  int stR = 158;
  int stG = 255;
  int stB = 169;
  for(int i = 0;i<5;i++)
  {
    int tempR = (float)stR*map(i, 4, 0, 10, 4)/10;
    int tempG = (float)stG*map(i, 4, 0, 10, 4)/10;
    int tempB = (float)stB*map(i, 4, 0, 10, 4)/10;
    uint16_t temp565 = tft.color565(tempR, tempG, tempB);
    colors[i] = temp565;
  }
  tft.setTextFont(2);
}

void drawText(uint8_t i)
{
  int start = startPoints[i]*18;
  int xPos = i*20;
  tft.fillRect(xPos,start,20,18,TFT_BLACK);
  for(int j = 1;j<6;j++)
  {
    int yPos = start + j*18;
    if (yPos>=320)yPos-=324;
    uint16_t colorTemp = colors[j-1];
    tft.setTextColor(colorTemp);
    tft.fillRect(xPos,yPos,20,18,TFT_BLACK);
    tft.drawChar((65 + random(0,2)*32 + random(0,25)), xPos, yPos, 2);
  }
  startPoints[i] = startPoints[i] + 1;
  if(startPoints[i]>=18)startPoints[i] = 0;
}

void loop() {
  // put your main code here, to run repeatedly:
  drawText(0);
  drawText(1);
  drawText(2);
  drawText(4);
  drawText(5);
  drawText(6);
  drawText(8);
  drawText(10);
  drawText(11);
  delay(150);
}

实现的是文字逐位下移的效果

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值