Tarea Reconocimiento de voz (procesadores) unalmed 2017-2
Fork of serialrecibe1 by
main.cpp@2:638f033a8650, 2017-11-24 (annotated)
- Committer:
- CarolinaV
- Date:
- Fri Nov 24 20:11:55 2017 +0000
- Revision:
- 2:638f033a8650
- Parent:
- 1:bf58c37db6af
Tarea Reconocimiento de voz unal-med
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 1:bf58c37db6af | 1 | //PROGRAMA PARA RECIBIR CARACTERES DESDE EL PC Y ACTIVAR 3 LEDS |
tony63 | 0:9894ad6153eb | 2 | //UTIL EN LECTURA DE CADENAS PARA APP INVENTOR |
tony63 | 0:9894ad6153eb | 3 | #include "mbed.h" |
tony63 | 0:9894ad6153eb | 4 | #include "stdio.h" |
tony63 | 0:9894ad6153eb | 5 | #include "string.h" |
CarolinaV | 2:638f033a8650 | 6 | #include "TextLCD.h" |
tony63 | 1:bf58c37db6af | 7 | |
tony63 | 0:9894ad6153eb | 8 | Serial GSM(PTE0,PTE1); //puertos del FRDM para el modem |
tony63 | 0:9894ad6153eb | 9 | Serial pc(USBTX,USBRX); //puertos del PC |
CarolinaV | 2:638f033a8650 | 10 | TextLCD lcd(PTA2, PTA1, PTA17, PTE31, PTD6, PTD7, TextLCD::LCD16x2); //rs, e, d4-d7 |
tony63 | 1:bf58c37db6af | 11 | char buffer[20];// TAMAÑO DEL BUFER |
tony63 | 0:9894ad6153eb | 12 | Timer t; //VALOR DEL TIEMPO |
tony63 | 0:9894ad6153eb | 13 | int count; |
tony63 | 0:9894ad6153eb | 14 | int i = 0; |
tony63 | 0:9894ad6153eb | 15 | int c=0; |
tony63 | 0:9894ad6153eb | 16 | char r[]=""; |
tony63 | 1:bf58c37db6af | 17 | char Qr[]="qmAIzQGtSK"; |
tony63 | 1:bf58c37db6af | 18 | DigitalOut LedRojo(LED1); |
tony63 | 1:bf58c37db6af | 19 | DigitalOut LedVerde(LED2); |
tony63 | 1:bf58c37db6af | 20 | DigitalOut LedAzul(LED3); |
tony63 | 0:9894ad6153eb | 21 | |
tony63 | 0:9894ad6153eb | 22 | int readBuffer(char *buffer,int count) //esta funcion lee un bufer de datos |
tony63 | 0:9894ad6153eb | 23 | { |
tony63 | 0:9894ad6153eb | 24 | int i=0; |
tony63 | 0:9894ad6153eb | 25 | t.start(); //CUENTA EL TIEMPO DE CONEXION E INICIA |
tony63 | 0:9894ad6153eb | 26 | while(1) { |
tony63 | 0:9894ad6153eb | 27 | while (GSM.readable()) { |
tony63 | 0:9894ad6153eb | 28 | char c = GSM.getc(); |
tony63 | 1:bf58c37db6af | 29 | if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracter inserta $ |
tony63 | 0:9894ad6153eb | 30 | buffer[i++] = c;//mete al bufer el caracter leido |
tony63 | 0:9894ad6153eb | 31 | if(i > count)break;//sale del loop si ya detecto terminacion |
tony63 | 0:9894ad6153eb | 32 | } |
tony63 | 0:9894ad6153eb | 33 | if(i > count)break; |
tony63 | 0:9894ad6153eb | 34 | if(t.read() > 1) { //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE |
tony63 | 0:9894ad6153eb | 35 | t.stop(); |
tony63 | 0:9894ad6153eb | 36 | t.reset(); |
tony63 | 0:9894ad6153eb | 37 | break; |
tony63 | 0:9894ad6153eb | 38 | } |
tony63 | 0:9894ad6153eb | 39 | } |
tony63 | 0:9894ad6153eb | 40 | return 0; |
tony63 | 0:9894ad6153eb | 41 | } |
tony63 | 0:9894ad6153eb | 42 | |
tony63 | 0:9894ad6153eb | 43 | void cleanBuffer(char *buffer, int count) //esta funcion limpia el bufer |
tony63 | 0:9894ad6153eb | 44 | { |
tony63 | 0:9894ad6153eb | 45 | for(int i=0; i < count; i++) { |
tony63 | 0:9894ad6153eb | 46 | buffer[i] = '\0'; |
tony63 | 0:9894ad6153eb | 47 | } |
tony63 | 0:9894ad6153eb | 48 | } |
tony63 | 0:9894ad6153eb | 49 | |
tony63 | 0:9894ad6153eb | 50 | |
tony63 | 0:9894ad6153eb | 51 | int main(void) |
tony63 | 0:9894ad6153eb | 52 | { |
CarolinaV | 2:638f033a8650 | 53 | |
tony63 | 0:9894ad6153eb | 54 | LedRojo=1; |
tony63 | 0:9894ad6153eb | 55 | LedAzul=1; |
tony63 | 0:9894ad6153eb | 56 | LedVerde=0; |
CarolinaV | 2:638f033a8650 | 57 | pc.printf("Hola Rosada"); |
CarolinaV | 2:638f033a8650 | 58 | lcd.printf("Hola Rosada"); |
tony63 | 0:9894ad6153eb | 59 | wait(2); //PRENDE EL LED VERDE POR 2 SEGUNDOS |
tony63 | 0:9894ad6153eb | 60 | LedVerde=1; |
tony63 | 0:9894ad6153eb | 61 | GSM.baud(9600); |
tony63 | 0:9894ad6153eb | 62 | GSM.format(8,Serial::None,1); |
tony63 | 1:bf58c37db6af | 63 | |
CarolinaV | 2:638f033a8650 | 64 | while(1){ |
CarolinaV | 2:638f033a8650 | 65 | |
tony63 | 0:9894ad6153eb | 66 | if (GSM.readable()) { |
tony63 | 1:bf58c37db6af | 67 | readBuffer(buffer,10); |
tony63 | 0:9894ad6153eb | 68 | pc.printf("buffer= %s\n\r ",buffer); //imprime el bufer |
tony63 | 0:9894ad6153eb | 69 | pc.printf("buffer= %c %c\n\r ",buffer[0],buffer[1]);//imprime el cero y el uno |
tony63 | 1:bf58c37db6af | 70 | |
CarolinaV | 2:638f033a8650 | 71 | if(buffer[0]=='3'){ |
CarolinaV | 2:638f033a8650 | 72 | |
CarolinaV | 2:638f033a8650 | 73 | lcd.cls(); |
CarolinaV | 2:638f033a8650 | 74 | lcd.locate(0, 0); |
CarolinaV | 2:638f033a8650 | 75 | lcd.printf("Verde"); |
CarolinaV | 2:638f033a8650 | 76 | |
CarolinaV | 2:638f033a8650 | 77 | }//PRENDE EL LED VERDE |
CarolinaV | 2:638f033a8650 | 78 | |
CarolinaV | 2:638f033a8650 | 79 | if( buffer[0]=='4'){ |
CarolinaV | 2:638f033a8650 | 80 | lcd.cls(); |
CarolinaV | 2:638f033a8650 | 81 | lcd.locate(0, 0); |
CarolinaV | 2:638f033a8650 | 82 | lcd.printf("Amarillo"); |
CarolinaV | 2:638f033a8650 | 83 | } //APAGA EL LED VERDE |
tony63 | 1:bf58c37db6af | 84 | |
CarolinaV | 2:638f033a8650 | 85 | if( buffer[0]=='1'){ |
CarolinaV | 2:638f033a8650 | 86 | LedRojo=0; |
CarolinaV | 2:638f033a8650 | 87 | lcd.cls(); |
CarolinaV | 2:638f033a8650 | 88 | lcd.locate(0, 0); |
CarolinaV | 2:638f033a8650 | 89 | lcd.printf("Rojo"); |
CarolinaV | 2:638f033a8650 | 90 | } //PRENDE EL LED ROJO |
tony63 | 1:bf58c37db6af | 91 | |
CarolinaV | 2:638f033a8650 | 92 | if( buffer[0]=='2'){ |
CarolinaV | 2:638f033a8650 | 93 | LedRojo=1; |
CarolinaV | 2:638f033a8650 | 94 | lcd.cls(); |
CarolinaV | 2:638f033a8650 | 95 | lcd.locate(0, 0); |
CarolinaV | 2:638f033a8650 | 96 | lcd.printf("Azul"); |
CarolinaV | 2:638f033a8650 | 97 | } //APAGA EL LED ROJO |
tony63 | 1:bf58c37db6af | 98 | |
tony63 | 1:bf58c37db6af | 99 | |
tony63 | 1:bf58c37db6af | 100 | |
tony63 | 0:9894ad6153eb | 101 | } |
CarolinaV | 2:638f033a8650 | 102 | cleanBuffer(buffer,10); |
CarolinaV | 2:638f033a8650 | 103 | } |
tony63 | 0:9894ad6153eb | 104 | } |