Dependencies:   mbed

Revision:
1:a149bb0c3d05
Parent:
0:389db7a2ed7f
Child:
2:bdc32e32f6f1
--- a/main.cpp	Thu Mar 05 15:31:52 2015 +0000
+++ b/main.cpp	Thu Mar 05 21:56:11 2015 +0000
@@ -1,8 +1,9 @@
 #include "mbed.h"
+#include <string>
 
 //------------------------------------
 // Hyperterminal configuration
-// 9600 bauds, 8-bit data, no parity
+// 115200 bauds, 8-bit data, no parity
 //------------------------------------
 void flushSerialPort(Serial* port);
 
@@ -12,20 +13,35 @@
 
 int main()
 {
-
+    int i;
+    char text[255];
+    
+    
     pc.baud(115200);
-    int i = 1;
-    int q;
+    i=1;
     pc.printf("Hello World !\n");
+    
+    
     while(1) {
         
-        wait(5);
-        pc.printf("This program runs since %d seconds.\n", i++);
+        wait(1);
+        pc.printf("You can tell me anything and I will repeat it...\n");
         myled = !myled;
-        flushSerialPort(&pc);
+        
         
-        if (pc.scanf("%d", &q))        
-            pc.printf("%d\n", q);
+        //NOTE: the data must be terminated with CR(Carriage return)
+        //NOTE: I had no luck using scanf() - it just scans an empty string.
+        i=0;
+        while (text[i-1] != '\r'){
+            if (pc.readable()){
+                text[i++] = getc(pc);
+            }            
+        }
+        
+        pc.printf("Received data: %s", text);
+        memset(&text, 0, i);
+        //flushSerialPort(&pc);
+        
     }
 }