Advertisement
otakus

Untitled

Jul 1st, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1.  
  2. void setup(){
  3.   Serial.begin(9600);
  4. }
  5.  
  6. void loop(){
  7.   Serial.println("Send any number 0-3 digits");
  8.   getInput();
  9. }
  10.  
  11. int getInput(){
  12.    int serAva;                           // i is a counter, serAva hold number of serial available
  13.    char inByte;
  14.    char inputBytes [4]={'\0','\0','\0','\0'};                 // Array hold input bytes
  15.        
  16.    while ((serAva=Serial.available()) <= 0) {  //set serAva to how many bytes are available and wait until data arrives
  17.     delay(50);
  18.    }
  19.    Serial.print("Bytes available: ");
  20.    Serial.println(serAva);
  21.    for(int i=0;i<serAva;i++){                  //itterate through all the bytes present
  22.      inputBytes[i]=Serial.read();              //Store the byte into array
  23.      Serial.println(inputBytes);             //debug for varification
  24.    }
  25.    return atoi(inputBytes);    // Call atoi function and return result
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement