PROGRAMA PARA HACER CONTROL DISCRETO POR BLUETOOTH ACIVA EN MODO TOGGLE, LOS MANDOS TOS ONV, ONR, ONA...QUE HACEN MENCION A ROJO VERDE, AZUL.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tony63
Date:
Fri Mar 31 04:32:00 2017 +0000
Commit message:
PROGRAMA PARA HACER CONTROL DISCRETO POR BLUETOOTH ACIVA EN MODO TOGGLE, LOS MANDOS TOS ONV, ONR, ONA...QUE HACEN MENCION A ROJO VERDE, AZUL.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 62e15126246b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 31 04:32:00 2017 +0000
@@ -0,0 +1,80 @@
+//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"
+ 
+Serial GSM(PTE0,PTE1);  //puertos del FRDM para el modem
+Serial pc(USBTX,USBRX); //puertos del PC
+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
+{
+    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 caracter 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); 
+               
+       while(1){ 
+       if (GSM.readable()) {
+          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' && buffer[2]=='A' ){LedAzul=!LedAzul;}  //PRENDE EL LED AZUL toggle
+          //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=!LedVerde;}//PRENDE EL LED VERDE toggle
+         //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=!LedRojo;}  //PRENDE EL LED ROJO toggle
+          //if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='R'){LedRojo=1;}  //APAGA EL LED ROJO
+          
+          
+          
+          } 
+          cleanBuffer(buffer,10);           
+}
+}
\ No newline at end of file
diff -r 000000000000 -r 62e15126246b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 31 04:32:00 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f
\ No newline at end of file