Advertisement
otakus

Untitled

Jul 1st, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. int getInput(){
  2.    int serAva;                           // i is a counter, serAva hold number of serial available
  3.    char inByte;
  4.    char inputBytes [4]={'\0','\0','\0','\0'};                 // Array hold input bytes
  5.    char * inputBytesPtr = &inputBytes[0];  // Pointer to the first element of the array
  6.        
  7.    while ((serAva=Serial.available()) <= 0) {  //set serAva to how many bytes are available and wait until data arrives
  8.     delay(50);
  9.    }
  10.    Serial.print("Bytes available: ");
  11.    Serial.println(serAva);
  12.    for(int i=0;i<serAva;i++){                  //itterate through all the bytes present
  13.      inputBytes[i]=Serial.read();              //Store the byte into array
  14.      Serial.println(inputBytes[i]);             //debug for varification
  15.    }
  16.    return atoi(inString);    // Call atoi function and return result
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement