marohito takami / Mbed 2 deprecated atoi_test

Dependencies:   mbed

Fork of Keyboard_Interrupt by marohito takami

Revision:
2:1432d7c567f4
Parent:
1:5440b3d7f435
diff -r 5440b3d7f435 -r 1432d7c567f4 main.cpp
--- a/main.cpp	Tue Jun 02 03:00:32 2015 +0000
+++ b/main.cpp	Tue Jun 02 08:51:43 2015 +0000
@@ -1,14 +1,36 @@
 #include "mbed.h"
+#include <string.h>
+
+//If you type more than two numbers, then type Enter, you get connected number.
 
 Serial pc(SERIAL_TX, SERIAL_RX);
 
+char line[16];
+
+int counter = 0;
+
 void my_Interrupt(){
     char key;
     key = pc.getc();
+    int number = int(key-'0');
+    if( (number > 9 || number < 0) && key!='\r'){
+        pc.printf("you can type only number, you cannot use dot.\r\n");
+        goto skip;
+    }
+    if(key == '\r'){
+        pc.printf("Enter\r\n");
+        pc.printf("%d\r\n", atoi(line));
+        counter=0;
+        goto skip;
+    }
+    line[counter] = key;
+    counter++;
     pc.printf("Interrupted %c\r\n", key);
+skip:
 }
 
 int main() {
+    memset(line, '\0', 16);
     pc.attach(my_Interrupt, Serial::RxIrq);
     while(1){}
 }