Sent data number exam2

Dependencies:   mbed strings

Files at this revision

API Documentation at this revision

Comitter:
NorNick
Date:
Tue Nov 17 09:37:38 2015 +0000
Parent:
0:7e5f31b719cf
Commit message:
Chang

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Oct 28 15:16:55 2015 +0000
+++ b/main.cpp	Tue Nov 17 09:37:38 2015 +0000
@@ -59,9 +59,9 @@
 BusOut ledSet2(D15, D14, D13, D12); //อย่าลืมกลับเลขด้วยเพราะมันต้องใช้ 7-Se
  
 int main(){
-    char value[100];
+    uint8_t value[100];
     int index=0;
-    char ch;
+    uint8_t ch;
     pc.printf("Hello Nucleo !\n");
     while(1){ 
     index = 0;
@@ -69,18 +69,50 @@
     { 
         if (pc.readable())      // if there is an character to read from the device
         {
-            //wait(0.75);
             ch = pc.getc();   // read it
-            pc.printf(" %c \n",ch);
-            if (index<100)               // just to avoid buffer overflow
-                value[index++]=ch;  // put it into the value array and increment the index
+            //if (index<100)               // just to avoid buffer overflow
+              //  value[index++]=ch;  // put it into the value array and increment the index
         }
-    } while (ch!='?');    // loop until the '\n' character
+    } while(index <= 99 && ch!='z' );    // loop until the '\n' character
+    ch = '\0';
     value[index]='\x0';  // add un 0 to end the c string
-    pc.printf(" %s \n",value);
+    //pc.printf("%s.\n",value);
     }
 }
+/*
 
+
+#include "mbed.h"
+ 
+//Serial micro(p9, p10);
+Serial pc(USBTX,USBRX);
+int err;
+char command[100];
+ 
+int main() {
+    /*micro.format(8, Serial::None, 1);
+    micro.baud(19200);
+    pc.format(8, Serial::None, 1);
+    pc.baud(9600);*/   /*
+ 
+    pc.printf("Hello Nucleo !\n");
+    while(1){
+    while (true) {       
+        if (pc.readable()) {
+            pc.scanf("%s",command);            
+            break;
+        }
+    }
+    pc.printf("Resulit: %s\n",command);
+    pc.printf("Command Received: \r\n");
+    for (int i=0;i<sizeof(command);i++){
+    pc.printf("%X",command[i]);
+    }
+    pc.printf("\r\n");
+    pc.printf("Scanf returns: %d\r\n",err);
+    }
+}
+*/
 /*
 #include "mbed.h"
 #include <string>