Andy Zucker / Mbed 2 deprecated serial_communication1

Dependencies:   mbed

Fork of serial_communication by Andy Zucker

Revision:
0:15ca75f6e1a0
Child:
1:32c006ad8eaf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Feb 21 14:10:38 2016 +0000
@@ -0,0 +1,72 @@
+#include "mbed.h"
+#include <string>
+
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+
+//***********************************************************************************
+//***Set up the Serial communication to your PC**************************************
+//***Type some Keys and when pressing enter, mbed will send some analyzed strings****
+//***********************************************************************************
+
+int main() 
+{
+    
+    char ch[40];
+    int count=0;
+    char buf1[30];
+    char buf2[30];
+    
+    while(1) 
+    {
+      
+      if(pc.readable())
+      {
+        
+        
+        //store char in char array (ch)
+        ch[count]= pc.getc();
+        //print out to PC for better visibility/response
+        pc.putc(ch[count]);
+        
+        //if receiving ENTER - print out everything and reset counter
+         if(ch[count] == '\r')
+         {
+          pc.printf("\n\rCharacters received: %d \n\r",count);
+          pc.printf("First three characters: %c%c%c \n\r",ch[0],ch[1],ch[2]);
+          pc.printf("Second three characters: %c%c%c \n\r",ch[3],ch[4],ch[5]); 
+          
+          
+               //devide ch array into two separate char arrays
+               sprintf(buf1,"%c%c%c",ch[0],ch[1],ch[2]);
+               sprintf(buf2,"%c%c%c",ch[3],ch[4],ch[5]);
+          
+               //***compare the two new char arrays***************************************************
+               if(strcmp(buf1,buf2) == 0)
+               {
+               pc.printf("First and second three characters are identicaly: %s \n\n\r",buf1);  
+               }
+               else
+               {
+               pc.printf("First and second three characters are not identicaly \n\n\r");
+               }
+               //****************************************************************************************
+          
+          count=0;
+          } 
+         
+         
+         
+         
+         //else count up and store all received char's in the array
+         else
+         {
+         count++; 
+         }
+        
+      }
+      
+      
+        
+    }
+}