一、修改LD7V语音识别模块代码
1、修改一级口令为“小没用”,二级口令为开盖与关盖
2、修改打印输出代码
二、树莓派端代码编写
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <softPwm.h>
#include <wiringPi.h>
#include <unistd.h>
#include <sys/time.h>
#include <wiringSerial.h>
#define SERVO 26
void raspberrySetup()
{
if(wiringPiSetup() < 0)
{
perror("树莓派启动失败\n");
exit(-1);//退出当前进程
}
}
int main()
{
char cmd[128]={'\0'};
raspberrySetup();//初始化树莓派
softPwmCreate(SERVO,0,200);
softPwmWrite(SERVO,15);//设置初始值关盖
int fd=serialOpen("/dev/ttyAMA0",9600);//打开并初始化串口,波特率设置为9600
if(fd !=-1)
{
printf("serial open success!\n");
}
while(1)
{
read(fd,cmd,sizeof(cmd));
if(strlen(cmd) == 0)
{
printf("recv overtime!\n");
continue;
}
if(strstr(cmd,"close") !=NULL)
{
softPwmWrite(SERVO,15);//关盖
printf("close success!\n");
}
if(strstr(cmd,"open") !=NULL)
{
softPwmWrite(SERVO,5);//开盖
printf("open success!\n");
}
memset(cmd,'\0',sizeof(cmd)/sizeof(char));//清空
}
return 0;
}