Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 //PROGRAMA PARA RECIBIR CARACTERES DESDE EL PC Y ACTIVAR 3 LEDS 00002 //UTIL EN LECTURA DE CADENAS PARA APP INVENTOR 00003 #include "mbed.h" 00004 #include "stdio.h" 00005 #include "string.h" 00006 00007 Serial GSM(PTE0,PTE1); //puertos del FRDM para el modem 00008 Serial pc(USBTX,USBRX); //puertos del PC 00009 char buffer[20];// TAMAÑO DEL BUFER 00010 Timer t; //VALOR DEL TIEMPO 00011 int count; 00012 int i = 0; 00013 int c=0; 00014 char r[]=""; 00015 char Qr[]="qmAIzQGtSK"; 00016 DigitalOut LedRojo(LED1); 00017 DigitalOut LedVerde(LED2); 00018 DigitalOut LedAzul(LED3); 00019 00020 int readBuffer(char *buffer,int count) //esta funcion lee un bufer de datos 00021 { 00022 int i=0; 00023 t.start(); //CUENTA EL TIEMPO DE CONEXION E INICIA 00024 while(1) { 00025 while (GSM.readable()) { 00026 char c = GSM.getc(); 00027 if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracter inserta $ 00028 buffer[i++] = c;//mete al bufer el caracter leido 00029 if(i > count)break;//sale del loop si ya detecto terminacion 00030 } 00031 if(i > count)break; 00032 if(t.read() > 1) { //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE 00033 t.stop(); 00034 t.reset(); 00035 break; 00036 } 00037 } 00038 return 0; 00039 } 00040 00041 void cleanBuffer(char *buffer, int count) //esta funcion limpia el bufer 00042 { 00043 for(int i=0; i < count; i++) { 00044 buffer[i] = '\0'; 00045 } 00046 } 00047 00048 00049 int main(void) 00050 { 00051 LedVerde=1; 00052 LedRojo=1; 00053 LedAzul=1; 00054 LedVerde=0; 00055 wait(2); //PRENDE EL LED VERDE POR 2 SEGUNDOS 00056 LedVerde=1; 00057 GSM.baud(9600); 00058 GSM.format(8,Serial::None,1); 00059 00060 while(1){ 00061 if (GSM.readable()) { 00062 readBuffer(buffer,10); 00063 pc.printf("buffer= %s\n\r ",buffer); //imprime el bufer 00064 pc.printf("buffer= %c %c\n\r ",buffer[0],buffer[1]);//imprime el cero y el uno 00065 00066 if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='A' ){LedAzul=!LedAzul;} //PRENDE EL LED AZUL toggle 00067 //if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='A'){LedAzul=1;} //APAGA EL LED AZUL 00068 00069 if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='V' ){LedVerde=!LedVerde;}//PRENDE EL LED VERDE toggle 00070 //if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='V'){LedVerde=1;} //APAGA EL LED VERDE 00071 00072 if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='R' ){LedRojo=!LedRojo;} //PRENDE EL LED ROJO toggle 00073 //if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='R'){LedRojo=1;} //APAGA EL LED ROJO 00074 00075 00076 00077 } 00078 cleanBuffer(buffer,10); 00079 } 00080 }
Generated on Fri Jul 29 2022 01:08:58 by
1.7.2