Arduino Serial Communication: Local Human Echo Input

I am using Arduino Duemilanove to run some tests. I communicate with arduin through the serial port. Everything that I try to do is read in several ints, and I use the parseInt () function for my simplicity.

My question is, is there a way to program ardunino to echo each character when it is entered, but still using the parseInt () function?

I know that there are usually options for enabling local echo in terminal clients, but I would rather not rely on them.

Here is the code I'm using:

    unsigned int timeTotal;
    Serial.print("Enter Total Time of Period (ms): "); 
    while (!Serial.available()) {   ;   }    //wait for input
    while (Serial.available() > 0) {
        //Serial.write(Serial.peek());
        timeTotal = Serial.parseInt();      //read int
        Serial.read();              //discard newline char at end of input
        Serial.println();
        Serial.print("Total Time: ");
        Serial.println(timeTotal, DEC);
    }

as you can see, I tried to use peek (), but only get one character from me ....

Thanks in advance!

+3
source share
1 answer

( , ), . atoi(). , , , parseInt .

+1

All Articles