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:
- 0:9894ad6153eb
- Child:
- 1:bf58c37db6af
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Apr 13 19:56:04 2015 +0000
@@ -0,0 +1,69 @@
+//PROGRAMA PARA RECIBIR CARACTERES DESDE EL PC Y ACTIVAR 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
+Timer t; //VALOR DEL TIEMPO
+int count;
+int i = 0;
+int c=0;
+char r[]="";
+
+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 caracxter 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)
+ {
+ LedVerde=1;
+ LedRojo=1;
+ LedAzul=1;
+ LedVerde=0;
+ wait(2); //PRENDE EL LED VERDE POR 2 SEGUNDOS
+ LedVerde=1;
+ GSM.baud(9600);
+ GSM.format(8,Serial::None,1);
+ LedVerde=0;
+
+ while(1){
+ if (GSM.readable()) {
+ readBuffer(buffer,5);
+ 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
+ }
+ cleanBuffer(buffer,5);
+}
+}
\ No newline at end of file