Advertisement
otakus

Untitled

Jul 1st, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. int getInput(){
  2.    int i, serAva;                           // i is a counter, serAva hold number of serial available
  3.    char inputBytes [4]={'0','0','0','\0'};                 // Array hold input bytes
  4.    char * inputBytesPtr = &inputBytes[0];  // Pointer to the first element of the array
  5.        
  6.    while((serAva=Serial.available())<=0){
  7.      delay(50);
  8.    }
  9.    for (i=0; i<serAva; i++){       // Load input bytes into array
  10.      int b=Serial.read();
  11.      Serial.print(b,DEC);
  12.      inputBytes[i+(3-serAva)] = b;
  13.    }
  14.    Serial.print(inputBytes[0]);
  15.    Serial.print(inputBytes[1]);
  16.    Serial.print(inputBytes[2]);
  17.    Serial.println(inputBytes[3]);
  18.    return atoi(inputBytesPtr);    // Call atoi function and return result
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement