Tarea Reconocimiento de voz (procesadores) unalmed 2017-2

Dependencies:   TextLCD mbed

Fork of serialrecibe1 by Gustavo Ramirez

main.cpp

Committer:
CarolinaV
Date:
2017-11-24
Revision:
2:638f033a8650
Parent:
1:bf58c37db6af

File content as of revision 2:638f033a8650:

//PROGRAMA PARA RECIBIR CARACTERES DESDE EL PC Y ACTIVAR 3 LEDS
//UTIL EN LECTURA DE CADENAS PARA APP INVENTOR
#include "mbed.h"
#include "stdio.h"
#include "string.h"
#include "TextLCD.h"
 
Serial GSM(PTE0,PTE1);  //puertos del FRDM para el modem
Serial pc(USBTX,USBRX); //puertos del PC
TextLCD lcd(PTA2, PTA1, PTA17, PTE31, PTD6, PTD7, TextLCD::LCD16x2); //rs, e, d4-d7
char buffer[20];// TAMAÑO DEL BUFER
Timer t;   //VALOR DEL TIEMPO
int count;
int i = 0;
int c=0;
char r[]=""; 
char Qr[]="qmAIzQGtSK";
DigitalOut LedRojo(LED1);
DigitalOut LedVerde(LED2);
DigitalOut LedAzul(LED3);
 
int readBuffer(char *buffer,int count)   //esta funcion lee un bufer de datos
{
    int i=0; 
    t.start();    //CUENTA EL TIEMPO DE CONEXION E INICIA
    while(1) {
        while (GSM.readable()) {
            char c = GSM.getc();
            if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracter inserta $
            buffer[i++] = c;//mete al bufer el caracter leido
            if(i > count)break;//sale del loop si ya detecto terminacion
        }
        if(i > count)break;
        if(t.read() > 1) {  //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE
            t.stop();
            t.reset();
            break;
        }
    }
     return 0;
}

void cleanBuffer(char *buffer, int count)  //esta funcion limpia el bufer
{
    for(int i=0; i < count; i++) {
        buffer[i] = '\0';
    }
}

   
int main(void)
       { 
             
       LedRojo=1;
       LedAzul=1;
       LedVerde=0;
pc.printf("Hola Rosada");
       lcd.printf("Hola Rosada");
       wait(2);   //PRENDE EL LED VERDE POR 2 SEGUNDOS
       LedVerde=1;
       GSM.baud(9600);
       GSM.format(8,Serial::None,1); 
               
       while(1){
            
       if (GSM.readable()) {
          readBuffer(buffer,10);
          pc.printf("buffer= %s\n\r ",buffer);  //imprime el bufer
          pc.printf("buffer= %c  %c\n\r ",buffer[0],buffer[1]);//imprime el cero y el uno
          
          if(buffer[0]=='3'){
            
            lcd.cls();
            lcd.locate(0, 0);
            lcd.printf("Verde");
            
            }//PRENDE EL LED VERDE
          
          if( buffer[0]=='4'){
              lcd.cls();
              lcd.locate(0, 0);
              lcd.printf("Amarillo");
              }  //APAGA EL LED VERDE
          
          if( buffer[0]=='1'){
              LedRojo=0;
              lcd.cls();
              lcd.locate(0, 0);
              lcd.printf("Rojo");
              }  //PRENDE EL LED ROJO
          
          if( buffer[0]=='2'){
              LedRojo=1;
              lcd.cls();
              lcd.locate(0, 0);
              lcd.printf("Azul");
              }  //APAGA EL LED ROJO
          
          
          
          } 
          cleanBuffer(buffer,10);
          }           
}