本帖最后由 大连林海 于 2015-2-8 09:40 编辑
语音控制调节台灯实现了全语音控制,它可以根据不同的语音命令作出开关和不同的动作,我们的台灯可以完成上、下、左、右、开、关、摇头、点头、跳舞的动作。其次,为了实现台灯的功能我们需要机械臂,一个Arduino控制板,一个扩展板,一个语音控制模块,一个升压模块,一个LED灯和电池。最后就是将这些零零散散的东西组装起来并编写程序,反复调试,直至它可以根据我们的命令准确无误的完成各种动作。
硬件完成的总效果图
换个角度
霸气的灯头部分
使用的是DFROBORT的mega1280和语音控制模块,最上面是V5扩展模块
使用的升压模块,给12V的LED供电
关灯后~
测试实际使用时的照明效果
一个比较“销魂”的角度
最后是程序源代码~
- #include "Voice.h" //申明语音识别库文件
- #include"Servo.h"
- Servo servo1; //duoji1
- Servo servo2; //duoji2
- Servo servo3; //duoji3
- #define SUM 28 //定义待识别的单词数量
- uint8 nAsrStatus=0; //申明语音模块工作状态
- int ledPin=6;
- int power1=20;
- int power2=20;
- int a=70,b=70,c=100;
- char sRecog[SUM][80] = //定义识别单词“拼音”内容的数组
- {"qian","hou","zuo","you","shang","xia","kai","kaideng","fuwei","guan","guandeng","yi","er","san"};
- char flag;//定义向上位机发送字符命令的变量
- //根据单词数组的元素号,执行相应命令
- void finally (unsigned char n)
- {
- switch(n)
- {
- case 0:
- b=b+power1;
- c=c+power1;
- if(b<145)
- servo2.write(b);//前进
- else
- servo2.write(b=b-power1);
- if(c>50)
- servo3.write(c);
- else
- servo3.write(c=c-power1);
- break;
- case 1:
- b=b-power1;
- c=c-power1;
- if(b>20)
- servo2.write(b); //后退
- else
- servo2.write(b=b+power1);
- if(c<160)
- servo3.write(c);
- else
- servo3.write(c=c+power1);
- break;
- case 2:
- a=a-power2;
- if(a>0)
- servo1.write(a=a); //左转
- else
- servo1.write(a=a+power2);
- break;
- case 3:
- a=a+power2;
- if(a<150)
- servo1.write(a); //右转
- else
- servo1.write(a=a-power2);
- break;
- case 4:
- c=c+power1;
- if(c<160)
- servo3.write(c);//起
- else
- servo3.write(c=c-power1);
- break;
- case 5:
- c=c-power1;
- if(c>50)
- servo3.write(c);//xia
- else
- servo3.write(c=c+power1);
- break;
- case 6:
- servo1.write(a=70);//Begin
- servo2.write(b=70);
- servo3.write(c=100);
- digitalWrite(ledPin, HIGH); // sets the LED on
- break;
- case 7:
- servo1.write(a=70);//Begin
- servo2.write(b=70);
- servo3.write(c=100);
- digitalWrite(ledPin, HIGH); // sets the LED on
- break;
- case 8:
- servo1.write(a=70);//Begin
- servo2.write(b=70);
- servo3.write(c=100);
- digitalWrite(ledPin, HIGH); // sets the LED on
- break;
- case 9:
- servo1.write(a=70); //停止
- servo2.write(b=30);
- servo3.write(c=50);
- digitalWrite(ledPin, LOW); // sets the LED off
- break;
- case 10:
- servo1.write(a=70); //停止
- servo2.write(b=30);
- servo3.write(c=50);
- digitalWrite(ledPin, LOW); // sets the LED off
- break;
- case 11: //jiangnanSTYLE
- servo1.write(a=70);
- servo2.write(b=70);
- servo3.write(c=100);
- for(int j=0;j<5;j++)
- {
- digitalWrite(ledPin, HIGH); // sets the LED on
- delay(1000);
- digitalWrite(ledPin,LOW); // sets the LED off
- delay(1000);
- }
- digitalWrite(ledPin, HIGH); // sets the LED on
- for(a;a>=30;a=a-5)
- {
- servo1.write(a);
- delay(100);
- }
- delay(1000);
- for(int i=0;i<3;i++)
- {
- for(c;c<115;c=c+5)
- {
- servo3.write(c);
- delay(100);
- }
- for(c;c>85;c=c-5)
- {
- servo3.write(c);
- delay(100);
- }
- }
- delay(500);
- for(a;a<=120;a=a+5)
- {
- servo1.write(a);
- delay(100);
- }
- delay(1000);
- for(int i=0;i<3;i++)
- {
- for(c;c<115;c=c+5)
- {
- servo3.write(c);
- delay(100);
- }
- for(c;c>85;c=c-5)
- {
- servo3.write(c);
- delay(100);
- }
- }
- servo1.write(a=70);
- servo2.write(b=70);
- servo3.write(c=100);
- for(int i=0;i<5;i++)
- {
- for(b,c;b<105;b=b+5,c=c+7)
- {
- servo2.write(b);
- servo3.write(c);
- digitalWrite(ledPin, HIGH); // sets the LED on
- delay(50);
- digitalWrite(ledPin, LOW); // sets the LED off
- delay(50);
- }
- for(b,c;b>55;b=b-5,c=c-7)
- {
- servo2.write(b);
- servo3.write(c);
- digitalWrite(ledPin, HIGH); // sets the LED on
- delay(50);
- digitalWrite(ledPin, LOW); // sets the LED off
- delay(50);
- }
- }
- servo1.write(a=70);
- servo2.write(b=70);
- servo3.write(c=100);
- digitalWrite(ledPin, HIGH); // sets the LED on
- break;
- case 12: //yaotou
- servo1.write(a=70);
- for(int i=0;i<5;i++)
- {
- for(a;a>35;a=a-5)
- {
- servo1.write(a);
- delay(100);
- }
- for(a;a<105;a=a+5)
- {
- servo1.write(a);
- delay(100);
- }
- }
- servo1.write(a=70);
- break;
- case 13: //diantou
- servo3.write(c=100);
- for(int i=0;i<3;i++)
- {
- for(c;c<115;c=c+5)
- {
- servo3.write(c);
- delay(100);
- }
- for(c;c>85;c=c-5)
- {
- servo3.write(c);
- delay(100);
- }
- }
- servo3.write(c=100);
- break;
- default:
- break;
- }
- }
- //识别到声音,产生一个触发中断
- void ExtInt0Handler ()
- {
- Voice.ProcessInt0();//执行中断服务子程序
- }
- //初始化
- void setup()
- {
- servo1.attach(3);
- servo1.write(70);
- servo2.attach(5);
- servo2.write(70);
- servo3.attach(8);
- servo3.write(100);
- pinMode(ledPin, OUTPUT); // sets the digital pin as output
- digitalWrite(ledPin, HIGH); // sets the LED on
- Voice.Initialise(MIC);//初始化语音模块
- attachInterrupt(0,ExtInt0Handler,LOW);
- }
- //主程序
- void loop()
- {
- uint8 nAsrRes;
- nAsrStatus = LD_ASR_NONE;
- while(1)
- {
- //当语音模块处于各状态,执行相应工作
- switch(nAsrStatus)
- {
- case LD_ASR_RUNING:
- case LD_ASR_ERROR:
- break;
- case LD_ASR_NONE:
- {
- nAsrStatus=LD_ASR_RUNING;
- if (Voice.RunASR(SUM,80,sRecog)==0)
- {
- nAsrStatus= LD_ASR_ERROR;
- // Serial.println( "ASR_ERROR");
- }
- //Serial.println( "ASR_RUNING.....");
- break;
- }
- //识别到单词是设定单词
- case LD_ASR_FOUNDOK:
- {
- //Serial.print( "ASR_FOUN ONE: ");
- //提取所识别到的单词是数组的第几个元素
- nAsrRes =Voice. LD_GetResult();
- //根据数组元素号,执行相应命令
- finally(nAsrRes);
- nAsrStatus = LD_ASR_NONE;
- break;
- }
- //识别到单词“不是”设定单词
- case LD_ASR_FOUNDZERO:
- {
- //Serial.println( "ASR_FOUND ZERO");
- nAsrStatus = LD_ASR_NONE;
- break;
- }
- default:
- {
- nAsrStatus = LD_ASR_NONE;
- break;
- }
- }// switch
- delay(100); //yanshi 0.5s
- }// while
- }
复制代码
接下来是上视频短片~
|
|
|
|
|
|