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.
Diff: main.cpp
- Revision:
- 1:bf58c37db6af
- Parent:
- 0:9894ad6153eb
--- a/main.cpp Mon Apr 13 19:56:04 2015 +0000
+++ b/main.cpp Fri Mar 31 04:25:45 2017 +0000
@@ -1,19 +1,21 @@
-//PROGRAMA PARA RECIBIR CARACTERES DESDE EL PC Y ACTIVAR LEDS
+//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"
-DigitalOut LedVerde(LED2);
-DigitalOut LedRojo(LED1);
-DigitalOut LedAzul(LED3);
+
Serial GSM(PTE0,PTE1); //puertos del FRDM para el modem
Serial pc(USBTX,USBRX); //puertos del PC
-char buffer[5];// TAMAÑO DEL BUFER
+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
{
@@ -22,7 +24,7 @@
while(1) {
while (GSM.readable()) {
char c = GSM.getc();
- if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracxter inserta $
+ 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
}
@@ -54,16 +56,25 @@
LedVerde=1;
GSM.baud(9600);
GSM.format(8,Serial::None,1);
- LedVerde=0;
-
+
while(1){
if (GSM.readable()) {
- readBuffer(buffer,5);
+ 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]=='O' && buffer[1]=='N'){LedAzul=0;} //PRENDE EL LED AZUL
- if(buffer[0]=='O' && buffer[1]=='F'){LedAzul=1;} //APAGA EL LED AZUL
+
+ if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='A' ){LedAzul=0;} //PRENDE EL LED AZUL
+ if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='A'){LedAzul=1;} //APAGA EL LED AZUL
+
+ if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='V' ){LedVerde=0;}//PRENDE EL LED VERDE
+ if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='V'){LedVerde=1;} //APAGA EL LED VERDE
+
+ if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='R' ){LedRojo=0;} //PRENDE EL LED ROJO
+ if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='R'){LedRojo=1;} //APAGA EL LED ROJO
+
+
+
}
- cleanBuffer(buffer,5);
+ cleanBuffer(buffer,10);
}
}
\ No newline at end of file