/* ------------------------------------------------ * SERIAL COM - HANDELING MULTIPLE BYTES inside ARDUINO - 01_simple version * by beltran berrocal * * this prog establishes a connection with the pc and waits for it to send him * a long string of characters like "hello Arduino!". * Then Arduino informs the pc that it heard the whole sentence * * this is the first step for establishing sentence long conversations between arduino and the pc. * serialRead() reads one byte at a time from the serial buffer. * so in order to print out the whole sentence at once * (it is actually still printing one byte at a time but the pc will receive it * not interupted by newLines or other printString inside you loop) * You must loop untill there are bytes in the serial buffer and * and print right away that byte you just read. * after that the loop can continue it's tasks. * * created 15 Decembre 2005; * copyleft 2005 Progetto25zero1 * * --------------------------------------------------- */ int serIn; //var that will hold the bytes in read from the serialBuffer void setup() { Serial.begin(9600); } //auto go_to_the_line function //void printNewLine() { // Serial.print(13, BYTE); // Serial.print(10, BYTE); //} void loop () { //simple feedback from Arduino Serial.println("Hello World"); // only if there are bytes in the serial buffer execute the following code if(Serial.available()) { //inform that Arduino heard you saying something Serial.print("Arduino heard you say: "); //keep reading and printing from serial untill there are bytes in the serial buffer while (Serial.available()>0){ serIn = Serial.read(); //read Serial Serial.print(serIn, BYTE); //prints the character just read } //the serial buffer is over just go to the line (or pass your favorite stop char) Serial.println(); } //slows down the visualization in the terminal delay(1000); }