marohito takami / Mbed 2 deprecated atoi_test

Dependencies:   mbed

Fork of Keyboard_Interrupt by marohito takami

main.cpp

Committer:
TakamiMa
Date:
2015-06-02
Revision:
2:1432d7c567f4
Parent:
1:5440b3d7f435

File content as of revision 2:1432d7c567f4:

#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){}
}