Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup(){
- Serial.begin(9600);
- }
- void loop(){
- Serial.println("Send any number 0-3 digits");
- getInput();
- }
- int getInput(){
- int serAva; // i is a counter, serAva hold number of serial available
- char inByte;
- char inputBytes [4]={'\0','\0','\0','\0'}; // Array hold input bytes
- while ((serAva=Serial.available()) <= 0) { //set serAva to how many bytes are available and wait until data arrives
- delay(50);
- }
- Serial.print("Bytes available: ");
- Serial.println(serAva);
- for(int i=0;i<serAva;i++){ //itterate through all the bytes present
- inputBytes[i]=Serial.read(); //Store the byte into array
- Serial.println(inputBytes); //debug for varification
- }
- return atoi(inputBytes); // Call atoi function and return result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement