Dima Dudin / Mbed 2 deprecated DD_Robot

Dependencies:   mbed mbed-STM32F103C8T6 MPU6050_1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sound.h Source File

sound.h

00001 char sound_out_send_buf[10]= {0x7E, 0xFF, 06, 03, 00, 00, 00, 00, 00, 0xEF};
00002 char sound_in_receive_buf[64];
00003 int sound_in_receive_counter;
00004 
00005 void play(short int record_num){
00006     sound_out_send_buf[5] = (char)(record_num >> 8); //high byte
00007     sound_out_send_buf[6] = (char)record_num; //low byte
00008     short int sum = 0;
00009     for (int i=1; i<7; i++) sum -= sound_out_send_buf[i];
00010     sound_out_send_buf[7] = (char)(sum >> 8); //high byte
00011     sound_out_send_buf[8] = (char)sum; //low byte
00012     for (int i = 0; i < 10; i++) sound_out.putc(sound_out_send_buf[i]);
00013     }
00014 
00015 void start_recognizer(){
00016     sound_in.putc(0xAA);
00017     sound_in.putc(0x05); //0x09);  //2+N
00018     sound_in.putc(0x30); //command "Load to recognizer"
00019     sound_in.putc(0x00); //load command 00 to recognizer
00020     sound_in.putc(0x01);
00021     sound_in.putc(0x02);
00022 //    sound_in.putc(0x03);
00023 //    sound_in.putc(0x04);
00024 //    sound_in.putc(0x05);
00025 //    sound_in.putc(0x06); //load command 06 to recognizer
00026     sound_in.putc(0x0A);
00027     }
00028      
00029 
00030 void voice_command_process(){ 
00031     if(sound_in.readable()){
00032         //if (myled == 0 ) myled = 1;else myled = 0;
00033         char tmc = sound_in.getc();
00034         wifi.putc(tmc);
00035         if (tmc == 0xAA) sound_in_receive_counter = 0; else sound_in_receive_counter++; if(sound_in_receive_counter > 15) sound_in_receive_counter = 15;
00036         sound_in_receive_buf[sound_in_receive_counter] = tmc;
00037         if (sound_in_receive_counter == 5){
00038             switch(tmc){
00039                 case 0: play(rand()%10+1); break;
00040                 case 1: play(rand()%10+1); break;
00041                 case 2: play(rand()%10+1); break;
00042                 case 3: play(rand()%10+1); break;
00043                 case 4: play(1); break;
00044                 case 5: play(1); break;
00045                 case 6: play(1); break;
00046                 }
00047             }
00048         }
00049     }
00050     
00051     
00052 /*void sound_in_init(){
00053     sound_in.attach(&voice_command_receive);
00054     }*/