先上图片
演示视频
Max7219点阵的制作,请参考本人的另一个帖子:MAX7219LED点阵显示双位数字 https://mc.dfrobot.com.cn/thread-297748-1-1.html
倒计时结束时的爆炸音,是通过UART MP3语音模块实现。它的维库:https://wiki.dfrobot.com.cn/_SKU_DFR0534_Voice_Module
接线图
代码
#include <DFRobot_LedControl.h>
#include <DFRobot_SerialMp3.h>
#include <SoftwareSerial.h>
#include <DFRobot_Ultrasonic.h>
DFRobot_Ultrasonic ultraA0;
DFRobot_SerialMp3 serialMp3;
SoftwareSerial softSerialserialMp3(10, 11);
DFRobot_LedControl max7219(3, 5, 4);
const byte LedArray_left[10][8] = {{B00000000,B11100000,B10100000,B10100000,B10100000,B10100000,B10100000,B11100000},
{B00000000,B11000000,B01000000,B01000000,B01000000,B01000000,B01000000,B11100000},
{B00000000,B11100000,B00100000,B00100000,B11100000,B10000000,B10000000,B11100000},
{B00000000,B11100000,B00100000,B00100000,B11100000,B00100000,B00100000,B11100000},
{B00000000,B10100000,B10100000,B10100000,B11100000,B00100000,B00100000,B00100000},
{B00000000,B11100000,B10000000,B10000000,B11100000,B00100000,B00100000,B11100000},
{B00000000,B11100000,B10000000,B10000000,B11100000,B10100000,B10100000,B11100000},
{B00000000,B11100000,B00100000,B00100000,B00100000,B00100000,B00100000,B00100000},
{B00000000,B11100000,B10100000,B10100000,B11100000,B10100000,B10100000,B11100000},
{B00000000,B11100000,B10100000,B10100000,B11100000,B00100000,B00100000,B11100000}};
const byte LedArray_right[10][8] = {{B00000000,B00000111,B00000101,B00000101,B00000101,B00000101,B00000101,B00000111},
{B00000000,B00000110,B00000010,B00000010,B00000010,B00000010,B00000010,B00000111},
{B00000000,B00000111,B00000001,B00000001,B00000111,B00000100,B00000100,B00000111},
{B00000000,B00000111,B00000001,B00000001,B00000111,B00000001,B00000001,B00000111},
{B00000000,B00000101,B00000101,B00000101,B00000111,B00000001,B00000001,B00000001},
{B00000000,B00000111,B00000100,B00000100,B00000111,B00000001,B00000001,B00000111},
{B00000000,B00000111,B00000100,B00000100,B00000111,B00000101,B00000101,B00000111},
{B00000000,B00000111,B00000001,B00000001,B00000001,B00000001,B00000001,B00000001},
{B00000000,B00000111,B00000101,B00000101,B00000111,B00000101,B00000101,B00000111},
{B00000000,B00000111,B00000101,B00000101,B00000111,B00000001,B00000001,B00000111}};
byte show[]={B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
void setup() {
max7219.begin();
serialMp3.begin(&softSerialserialMp3);
serialMp3.play();
serialMp3.volume(99);
ultraA0.begin(A0);
}
void loop() {
int m;
int n;
for (int i = 99; i> 0;i--) {
m=int(i/10);
n=i%10;
for (int j = 0; j < 8; j++) {
show[j]=LedArray_left[m][j]+LedArray_right[n][j];
}
max7219.show(show);
if ((ultraA0.getDistanceCm() < 50)) {
break;
}
else{
delay(1000);
}
}
serialMp3.playList(17);
delay(5000);
}
橘子一只awa2022.05.08
看着有点吓人