boom表
语音识别模块LD3320
DHT11
TM1637
继电器
音乐盒
电机
L298N驱动
LED灯带WS2812
语音模块 LD3320 | 328P引脚 | Ardiuno 2560引脚 | leonardo | (AVR_ATmega32U4) |
MISO | ···········D12 | ···········D50 | ···········D14 | |
MOSI | ···········D11 | ···········D51 | ···········D16 | |
SCK | ···········D13 | ···········D52 | ···········D15 | |
NSS | ···········D4 | ···········D4 | ···········D4 | |
RS | ···········D9 | ···········D9 | ···········D9 | |
IRQ | ···········D2 | ···········D2 | ···········D2 | |
WR | ···········GND | ···········GND | ···········GND |
注意: 如果使用mega2560板,须先将ld3320.h文件中SPI pins部分进行修改 , 把10,11,12,13(默认为uno的SPI引脚),改为53,51,50,52(mega2560中的SPI引脚): // define software SPI pins /** SPI chip select pin */ uint8_t const LD_CHIP_SELECT_PIN = 53;//uno 10 /** SPI Master Out Slave In pin */ uint8_t const SPI_MOSI_PIN = 51;//uno 11; /** SPI Master In Slave Out pin */ uint8_t const SPI_MISO_PIN = 50;//uno 12; /** SPI Clock pin */ uint8_t const SPI_SCK_PIN =52;//uno 13; #endif // SOFTWARE_SPI
电路接线图
dht11= 5
数显模块 CLK =6
数显模块 DIO =7
Led = 8;
继电器 = 10;
风扇1 = 44;
风扇2 = 45;
语音模块 LD3320 ….Ardiuno 2560引脚
MISO…….D50
MOSI…….D51
SCK……D52
NSS……D4
RST……D9
IRQ……D2
WR……GND
代码实现
#include <dht.h>
#include "TM1637.h"
#include <ld3320.h> //加载模块库LD3320库文件视开发板芯片而定
VoiceRecognition Voice; //声明一个语音识别对象
int Led = 8; //定义LED控制引脚
int Music_d = 10;
int Fan_1 = 44;
int Fan_2 = 45;
#define dht_pin 5 // 温度模块
#define CLK 6 //数显模块
#define DIO 7
TM1637 tm1637(CLK, DIO);
dht DHT;
void setup() {
pinMode(Music_d, OUTPUT);
digitalWrite(Music_d, LOW);
pinMode(Led, OUTPUT);
digitalWrite(Led, LOW);
pinMode(Fan_1, OUTPUT);
pinMode(Fan_2, OUTPUT);
digitalWrite(Fan_1, LOW);
digitalWrite(Fan_2, LOW);
tm1637.init(); //数显模块
tm1637.set(BRIGHT_DARKEST);
//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
Voice.init(); //初始化VoiceRecognition模块
// char *led[] = {"kai deng","liang", "liang deng"};
// for(int i=0; i<=sizeof(led);i++){
// Voice.addCommand(led[i], 0);
// }
Voice.addCommand("kai deng", 0); //LED
Voice.addCommand("liang", 0);
Voice.addCommand("liang deng", 0);
Voice.addCommand("guan deng", 1);
Voice.addCommand("guan bi", 1);
Voice.addCommand("yin yue kai", 2); //音乐继电器
Voice.addCommand("yin yue", 2);
Voice.addCommand("kai yin yue", 2);
Voice.addCommand("yin yue guan", 3);
Voice.addCommand("guan yin yue", 3);
Voice.addCommand("wendu", 4); //温度
Voice.addCommand("wen du", 4);
Voice.addCommand("wen du xian shi", 4);
Voice.addCommand("guan wen du ", 5);
Voice.addCommand("guan bi wen du", 5);
Voice.addCommand("feng shan", 6); //电机风扇
Voice.addCommand("fen shan", 6);
Voice.addCommand("feng shan kai", 6);
Voice.addCommand("guan bi feng shan", 7);
Voice.addCommand("guan feng shan", 7);
Voice.addCommand("guan diao feng shan", 7);
Voice.addCommand("quan bu kai", 8); //all
Voice.addCommand("quan bu guan", 9);
Voice.addCommand("ni hao", 10); //添加垃圾词汇
Voice.addCommand("en", 10);
Voice.addCommand("wei", 10);
Voice.addCommand("a", 10);
Voice.addCommand("ei", 10);
Voice.addCommand("WO", 10);
Voice.start();
delay(500);
}
void Segled_on() {
//for ( int i = 1; i < 50 ; i++ ) {
DHT.read11(dht_pin);//温度
int temp = DHT.temperature;
int humidity = DHT.humidity;
int digitoneT = temp / 10;
int digittwoT = temp % 10;
int digitoneH = humidity / 10;
int digittwoH = humidity % 10;
tm1637.display(1, digitoneT);
tm1637.display(2, digittwoT);
tm1637.display(3, 12); // put a C at the end
delay (3000);
//}
}
void Segled_off() {
//for ( int i = 1; i < 50 ; i++ ) {
DHT.read11(dht_pin);
int temp = DHT.temperature;
int humidity = DHT.humidity;
int digitoneT = temp / 10;
int digittwoT = temp % 10;
int digitoneH = humidity / 10;
int digittwoH = humidity % 10;
tm1637.display(1, 0);
tm1637.display(2, 0);
tm1637.display(3, 0); // put a C at the end
//Wait 2 seconds before accessing sensor again.
//Fastest should be once every two seconds.
//}
}
void turn_on_all() {
digitalWrite(Led, HIGH);
digitalWrite(Music_d, HIGH);
digitalWrite(Fan_1, LOW); //低电平
digitalWrite(Fan_2, HIGH); //高电平 //开启电机风扇
Segled_on();
}
void turn_off_all() {
digitalWrite(Led, LOW);
digitalWrite(Music_d, LOW);
digitalWrite(Fan_1, LOW); //低电平
digitalWrite(Fan_2, LOW); //高电平 //开启电机风扇
Segled_off();
}
void loop() {
switch (Voice.read()) //判断识别
{
case 0:
digitalWrite(Led, HIGH); //点亮LED
break;
case 1:
digitalWrite(Led, LOW); //熄灭LED
break;
case 2:
digitalWrite(Music_d, HIGH); //播放音乐
break;
case 3:
digitalWrite(Music_d, LOW); //停止播放
break;
case 4:
Segled_on(); //显示
case 5:
Segled_off();
case 6:
digitalWrite(Fan_1, LOW); //低电平
digitalWrite(Fan_2, HIGH); //高电平
break;
case 7:
digitalWrite(Fan_1, LOW); //给低电平
digitalWrite(Fan_2, LOW); //给低电平
break;
case 8:
turn_on_all();
break;
case 9:
turn_off_all();
break;
case 10:
; //空语句
break;
default:
break;
}
}
关键词__对应操作
开灯,亮,亮灯……LED开
关灯,关闭……LED关
开音乐,音乐,音乐开……继电器开
音乐关,关音乐……继电器关
温度 温度显示……打开温度显示
关温度,关闭温度……关闭温度显示
风扇,风扇开……风扇开
关闭风扇,关风扇,关掉风扇……风扇关
全部开……全部开
全部关……全部关
参考
联系方式
Any question connect me.
ccwanyuan2014@163.com
提issue
转载请注明
转载自chanjeff123.github.io
本站文章请勿直接转载,转载前请务必署名
最后编辑时间为:2019-07-03 13:53:30