Advertisement
otakus

Untitled

Jul 1st, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #define INPUT_DIGIT_LIMIT 5
  2.  
  3. void setup(){
  4.   Serial.begin(9600);
  5. }
  6.  
  7. void loop(){
  8.   Serial.print("Send any number 0-");
  9.   Serial.print(INPUT_DIGIT_LIMIT);
  10.   Serial.print(" digits. ");
  11.   int num=getInput();
  12.   Serial.print("Received number: ");
  13.   Serial.println(num);
  14. }
  15.  
  16. int getInput(){
  17.    int counter=0;
  18.    char inputByte;
  19.    char inputBytes[INPUT_DIGIT_LIMIT+1];
  20.    do{
  21.      while(!Serial.available());
  22.        inputByte=Serial.read();
  23.        inputBytes[counter++]=inputByte;
  24.        if(inputByte==10||inputByte==13||counter==INPUT_DIGIT_LIMIT)
  25.          break;
  26.    }while(true);
  27.    inputBytes[counter]='\n';
  28.    
  29.    return atoi(inputBytes);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement