Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int getInput(){
- int i, serAva; // i is a counter, serAva hold number of serial available
- char inputBytes [4]={'0','0','0','\0'}; // Array hold input bytes
- char * inputBytesPtr = &inputBytes[0]; // Pointer to the first element of the array
- while((serAva=Serial.available())<=0){
- delay(50);
- }
- for (i=0; i<serAva; i++){ // Load input bytes into array
- int b=Serial.read();
- Serial.print(b,DEC);
- inputBytes[i+(3-serAva)] = b;
- }
- Serial.print(inputBytes[0]);
- Serial.print(inputBytes[1]);
- Serial.print(inputBytes[2]);
- Serial.println(inputBytes[3]);
- return atoi(inputBytesPtr); // Call atoi function and return result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement