Este programa se usa en recepcion de cadenas de caracteres, util para probar programas de conexion bluetooth en APPINVENTOR
/media/uploads/tony63/voz1.apk
/media/uploads/tony63/voz1.aia
main.cpp@1:bf58c37db6af, 2017-03-31 (annotated)
- Committer:
- tony63
- Date:
- Fri Mar 31 04:25:45 2017 +0000
- Revision:
- 1:bf58c37db6af
- Parent:
- 0:9894ad6153eb
PROGRAMA PARA PASAR CADENAS POR BLUETOOTH A TRES LED ESTA ACTUALIZADO
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" |
tony63 | 1:bf58c37db6af | 6 | |
tony63 | 0:9894ad6153eb | 7 | Serial GSM(PTE0,PTE1); //puertos del FRDM para el modem |
tony63 | 0:9894ad6153eb | 8 | Serial pc(USBTX,USBRX); //puertos del PC |
tony63 | 1:bf58c37db6af | 9 | char buffer[20];// TAMAÑO DEL BUFER |
tony63 | 0:9894ad6153eb | 10 | Timer t; //VALOR DEL TIEMPO |
tony63 | 0:9894ad6153eb | 11 | int count; |
tony63 | 0:9894ad6153eb | 12 | int i = 0; |
tony63 | 0:9894ad6153eb | 13 | int c=0; |
tony63 | 0:9894ad6153eb | 14 | char r[]=""; |
tony63 | 1:bf58c37db6af | 15 | char Qr[]="qmAIzQGtSK"; |
tony63 | 1:bf58c37db6af | 16 | DigitalOut LedRojo(LED1); |
tony63 | 1:bf58c37db6af | 17 | DigitalOut LedVerde(LED2); |
tony63 | 1:bf58c37db6af | 18 | DigitalOut LedAzul(LED3); |
tony63 | 0:9894ad6153eb | 19 | |
tony63 | 0:9894ad6153eb | 20 | int readBuffer(char *buffer,int count) //esta funcion lee un bufer de datos |
tony63 | 0:9894ad6153eb | 21 | { |
tony63 | 0:9894ad6153eb | 22 | int i=0; |
tony63 | 0:9894ad6153eb | 23 | t.start(); //CUENTA EL TIEMPO DE CONEXION E INICIA |
tony63 | 0:9894ad6153eb | 24 | while(1) { |
tony63 | 0:9894ad6153eb | 25 | while (GSM.readable()) { |
tony63 | 0:9894ad6153eb | 26 | char c = GSM.getc(); |
tony63 | 1:bf58c37db6af | 27 | if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracter inserta $ |
tony63 | 0:9894ad6153eb | 28 | buffer[i++] = c;//mete al bufer el caracter leido |
tony63 | 0:9894ad6153eb | 29 | if(i > count)break;//sale del loop si ya detecto terminacion |
tony63 | 0:9894ad6153eb | 30 | } |
tony63 | 0:9894ad6153eb | 31 | if(i > count)break; |
tony63 | 0:9894ad6153eb | 32 | if(t.read() > 1) { //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE |
tony63 | 0:9894ad6153eb | 33 | t.stop(); |
tony63 | 0:9894ad6153eb | 34 | t.reset(); |
tony63 | 0:9894ad6153eb | 35 | break; |
tony63 | 0:9894ad6153eb | 36 | } |
tony63 | 0:9894ad6153eb | 37 | } |
tony63 | 0:9894ad6153eb | 38 | return 0; |
tony63 | 0:9894ad6153eb | 39 | } |
tony63 | 0:9894ad6153eb | 40 | |
tony63 | 0:9894ad6153eb | 41 | void cleanBuffer(char *buffer, int count) //esta funcion limpia el bufer |
tony63 | 0:9894ad6153eb | 42 | { |
tony63 | 0:9894ad6153eb | 43 | for(int i=0; i < count; i++) { |
tony63 | 0:9894ad6153eb | 44 | buffer[i] = '\0'; |
tony63 | 0:9894ad6153eb | 45 | } |
tony63 | 0:9894ad6153eb | 46 | } |
tony63 | 0:9894ad6153eb | 47 | |
tony63 | 0:9894ad6153eb | 48 | |
tony63 | 0:9894ad6153eb | 49 | int main(void) |
tony63 | 0:9894ad6153eb | 50 | { |
tony63 | 0:9894ad6153eb | 51 | LedVerde=1; |
tony63 | 0:9894ad6153eb | 52 | LedRojo=1; |
tony63 | 0:9894ad6153eb | 53 | LedAzul=1; |
tony63 | 0:9894ad6153eb | 54 | LedVerde=0; |
tony63 | 0:9894ad6153eb | 55 | wait(2); //PRENDE EL LED VERDE POR 2 SEGUNDOS |
tony63 | 0:9894ad6153eb | 56 | LedVerde=1; |
tony63 | 0:9894ad6153eb | 57 | GSM.baud(9600); |
tony63 | 0:9894ad6153eb | 58 | GSM.format(8,Serial::None,1); |
tony63 | 1:bf58c37db6af | 59 | |
tony63 | 0:9894ad6153eb | 60 | while(1){ |
tony63 | 0:9894ad6153eb | 61 | if (GSM.readable()) { |
tony63 | 1:bf58c37db6af | 62 | readBuffer(buffer,10); |
tony63 | 0:9894ad6153eb | 63 | pc.printf("buffer= %s\n\r ",buffer); //imprime el bufer |
tony63 | 0:9894ad6153eb | 64 | pc.printf("buffer= %c %c\n\r ",buffer[0],buffer[1]);//imprime el cero y el uno |
tony63 | 1:bf58c37db6af | 65 | |
tony63 | 1:bf58c37db6af | 66 | if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='A' ){LedAzul=0;} //PRENDE EL LED AZUL |
tony63 | 1:bf58c37db6af | 67 | if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='A'){LedAzul=1;} //APAGA EL LED AZUL |
tony63 | 1:bf58c37db6af | 68 | |
tony63 | 1:bf58c37db6af | 69 | if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='V' ){LedVerde=0;}//PRENDE EL LED VERDE |
tony63 | 1:bf58c37db6af | 70 | if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='V'){LedVerde=1;} //APAGA EL LED VERDE |
tony63 | 1:bf58c37db6af | 71 | |
tony63 | 1:bf58c37db6af | 72 | if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='R' ){LedRojo=0;} //PRENDE EL LED ROJO |
tony63 | 1:bf58c37db6af | 73 | if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='R'){LedRojo=1;} //APAGA EL LED ROJO |
tony63 | 1:bf58c37db6af | 74 | |
tony63 | 1:bf58c37db6af | 75 | |
tony63 | 1:bf58c37db6af | 76 | |
tony63 | 0:9894ad6153eb | 77 | } |
tony63 | 1:bf58c37db6af | 78 | cleanBuffer(buffer,10); |
tony63 | 0:9894ad6153eb | 79 | } |
tony63 | 0:9894ad6153eb | 80 | } |