Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define INPUT_DIGIT_LIMIT 5
- void setup(){
- Serial.begin(9600);
- }
- void loop(){
- Serial.print("Send any number 0-");
- Serial.print(INPUT_DIGIT_LIMIT);
- Serial.print(" digits. ");
- int num=getInput();
- Serial.print("Received number: ");
- Serial.println(num);
- }
- int getInput(){
- int counter=0;
- char inputByte;
- char inputBytes[INPUT_DIGIT_LIMIT+1];
- do{
- while(!Serial.available());
- inputByte=Serial.read();
- inputBytes[counter++]=inputByte;
- if(inputByte==10||inputByte==13||counter==INPUT_DIGIT_LIMIT)
- break;
- }while(true);
- inputBytes[counter]='\n';
- return atoi(inputBytes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement