
PROGRAMA PARA HACER CONTROL DISCRETO POR BLUETOOTH ACIVA EN MODO TOGGLE, LOS MANDOS TOS ONV, ONR, ONA...QUE HACEN MENCION A ROJO VERDE, AZUL.
main.cpp@0:62e15126246b, 2017-03-31 (annotated)
- Committer:
- tony63
- Date:
- Fri Mar 31 04:32:00 2017 +0000
- Revision:
- 0:62e15126246b
PROGRAMA PARA HACER CONTROL DISCRETO POR BLUETOOTH ACIVA EN MODO TOGGLE, LOS MANDOS TOS ONV, ONR, ONA...QUE HACEN MENCION A ROJO VERDE, AZUL.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:62e15126246b | 1 | //PROGRAMA PARA RECIBIR CARACTERES DESDE EL PC Y ACTIVAR 3 LEDS |
tony63 | 0:62e15126246b | 2 | //UTIL EN LECTURA DE CADENAS PARA APP INVENTOR |
tony63 | 0:62e15126246b | 3 | #include "mbed.h" |
tony63 | 0:62e15126246b | 4 | #include "stdio.h" |
tony63 | 0:62e15126246b | 5 | #include "string.h" |
tony63 | 0:62e15126246b | 6 | |
tony63 | 0:62e15126246b | 7 | Serial GSM(PTE0,PTE1); //puertos del FRDM para el modem |
tony63 | 0:62e15126246b | 8 | Serial pc(USBTX,USBRX); //puertos del PC |
tony63 | 0:62e15126246b | 9 | char buffer[20];// TAMAÑO DEL BUFER |
tony63 | 0:62e15126246b | 10 | Timer t; //VALOR DEL TIEMPO |
tony63 | 0:62e15126246b | 11 | int count; |
tony63 | 0:62e15126246b | 12 | int i = 0; |
tony63 | 0:62e15126246b | 13 | int c=0; |
tony63 | 0:62e15126246b | 14 | char r[]=""; |
tony63 | 0:62e15126246b | 15 | char Qr[]="qmAIzQGtSK"; |
tony63 | 0:62e15126246b | 16 | DigitalOut LedRojo(LED1); |
tony63 | 0:62e15126246b | 17 | DigitalOut LedVerde(LED2); |
tony63 | 0:62e15126246b | 18 | DigitalOut LedAzul(LED3); |
tony63 | 0:62e15126246b | 19 | |
tony63 | 0:62e15126246b | 20 | int readBuffer(char *buffer,int count) //esta funcion lee un bufer de datos |
tony63 | 0:62e15126246b | 21 | { |
tony63 | 0:62e15126246b | 22 | int i=0; |
tony63 | 0:62e15126246b | 23 | t.start(); //CUENTA EL TIEMPO DE CONEXION E INICIA |
tony63 | 0:62e15126246b | 24 | while(1) { |
tony63 | 0:62e15126246b | 25 | while (GSM.readable()) { |
tony63 | 0:62e15126246b | 26 | char c = GSM.getc(); |
tony63 | 0:62e15126246b | 27 | if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracter inserta $ |
tony63 | 0:62e15126246b | 28 | buffer[i++] = c;//mete al bufer el caracter leido |
tony63 | 0:62e15126246b | 29 | if(i > count)break;//sale del loop si ya detecto terminacion |
tony63 | 0:62e15126246b | 30 | } |
tony63 | 0:62e15126246b | 31 | if(i > count)break; |
tony63 | 0:62e15126246b | 32 | if(t.read() > 1) { //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE |
tony63 | 0:62e15126246b | 33 | t.stop(); |
tony63 | 0:62e15126246b | 34 | t.reset(); |
tony63 | 0:62e15126246b | 35 | break; |
tony63 | 0:62e15126246b | 36 | } |
tony63 | 0:62e15126246b | 37 | } |
tony63 | 0:62e15126246b | 38 | return 0; |
tony63 | 0:62e15126246b | 39 | } |
tony63 | 0:62e15126246b | 40 | |
tony63 | 0:62e15126246b | 41 | void cleanBuffer(char *buffer, int count) //esta funcion limpia el bufer |
tony63 | 0:62e15126246b | 42 | { |
tony63 | 0:62e15126246b | 43 | for(int i=0; i < count; i++) { |
tony63 | 0:62e15126246b | 44 | buffer[i] = '\0'; |
tony63 | 0:62e15126246b | 45 | } |
tony63 | 0:62e15126246b | 46 | } |
tony63 | 0:62e15126246b | 47 | |
tony63 | 0:62e15126246b | 48 | |
tony63 | 0:62e15126246b | 49 | int main(void) |
tony63 | 0:62e15126246b | 50 | { |
tony63 | 0:62e15126246b | 51 | LedVerde=1; |
tony63 | 0:62e15126246b | 52 | LedRojo=1; |
tony63 | 0:62e15126246b | 53 | LedAzul=1; |
tony63 | 0:62e15126246b | 54 | LedVerde=0; |
tony63 | 0:62e15126246b | 55 | wait(2); //PRENDE EL LED VERDE POR 2 SEGUNDOS |
tony63 | 0:62e15126246b | 56 | LedVerde=1; |
tony63 | 0:62e15126246b | 57 | GSM.baud(9600); |
tony63 | 0:62e15126246b | 58 | GSM.format(8,Serial::None,1); |
tony63 | 0:62e15126246b | 59 | |
tony63 | 0:62e15126246b | 60 | while(1){ |
tony63 | 0:62e15126246b | 61 | if (GSM.readable()) { |
tony63 | 0:62e15126246b | 62 | readBuffer(buffer,10); |
tony63 | 0:62e15126246b | 63 | pc.printf("buffer= %s\n\r ",buffer); //imprime el bufer |
tony63 | 0:62e15126246b | 64 | pc.printf("buffer= %c %c\n\r ",buffer[0],buffer[1]);//imprime el cero y el uno |
tony63 | 0:62e15126246b | 65 | |
tony63 | 0:62e15126246b | 66 | if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='A' ){LedAzul=!LedAzul;} //PRENDE EL LED AZUL toggle |
tony63 | 0:62e15126246b | 67 | //if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='A'){LedAzul=1;} //APAGA EL LED AZUL |
tony63 | 0:62e15126246b | 68 | |
tony63 | 0:62e15126246b | 69 | if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='V' ){LedVerde=!LedVerde;}//PRENDE EL LED VERDE toggle |
tony63 | 0:62e15126246b | 70 | //if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='V'){LedVerde=1;} //APAGA EL LED VERDE |
tony63 | 0:62e15126246b | 71 | |
tony63 | 0:62e15126246b | 72 | if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='R' ){LedRojo=!LedRojo;} //PRENDE EL LED ROJO toggle |
tony63 | 0:62e15126246b | 73 | //if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='R'){LedRojo=1;} //APAGA EL LED ROJO |
tony63 | 0:62e15126246b | 74 | |
tony63 | 0:62e15126246b | 75 | |
tony63 | 0:62e15126246b | 76 | |
tony63 | 0:62e15126246b | 77 | } |
tony63 | 0:62e15126246b | 78 | cleanBuffer(buffer,10); |
tony63 | 0:62e15126246b | 79 | } |
tony63 | 0:62e15126246b | 80 | } |