Comunicación serial entre dos equipos.

Dependencies:   SoftSerial mbed

Revision:
1:25542223771f
Parent:
0:803792acd19e
--- a/main.cpp	Sat Sep 23 21:37:22 2017 +0000
+++ b/main.cpp	Sat Sep 30 21:26:05 2017 +0000
@@ -1,42 +1,31 @@
 #include "mbed.h"
 #include "SoftSerial.h"
 
-SoftSerial nucleo (D8,D9);
-Serial pc(SERIAL_TX, SERIAL_RX);
-char sent,rec;
-int i =0;
-int k =0;
-int main()
-{
-    char msm[25]= {};
-    char led[25]= {};
-    char com[3] = {'o','f','f'};
-
-    while(1) {
-
-        if (pc.readable()>0) {
-            sent=pc.getc();
-            if(sent == 13) {
-                for (int j = 0; j<i; j++) {
-                    nucleo.printf("%c",msm[j]);
-                    pc.printf("%c",msm[j]);
-               wait(0.01);}
-               nucleo.printf("\n\r");
-               pc.printf("\n\r");
-                i=0;
-            } else {
-                msm[i]=sent;
-                i++;
+Serial pc (USBTX,USBRX);
+SoftSerial bt(D2,D3);
+DigitalOut der(D9);
+DigitalOut izq(D8);
+int estado ;
+int main(){
+    while(1){
+        
+        if(bt.readable()>0)
+        {estado = bt.getc();
             }
+        if(estado == 1){   
+        der = 0;
+        izq = 1;
+        pc.printf("Izquierda; %d\n\r ",estado);
+        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
+        if(estado == 0){
+        izq = 0;
+        der = 1;
+        pc.printf("Derecha;%d\n\r",estado);
         }
-        if(nucleo.readable()>0) {
-             rec=nucleo.getc();             
-             pc.printf("%c",rec);
-     wait(0.01);
-     led[k]=rec; 
-     k++;
-     
-         }
-     
+        if(estado == 2){
+        izq = 0;
+        der = 0;
+        pc.printf("Stop;%d\n\r",estado);
+        }          
     }
-}
+    }
\ No newline at end of file