Reading multiple data streams from Serial

Hi All,

I'm hoping someone can help supply me with some code / suedo-code for a project I'm working on. Although I have experience with arduino, I've done very little serial communication.

I need to get the arduino to respond to specific input over serial from a terminal window.

In the terminal window, I'll be typing a 1 - 4 digit number, followed by a carriage return.

Ultimately I'd like this four digit number saved as an Int on the arduino.

I'm guessing each byte would need to be buffered until the carriage return is detected, but I'm having trouble working out how to do this.

If anyone could help it would be most appreciated.

Just looking for the code I`ve used :

if ( Serial.available() > 0) { // if there are bytes waiting on the serial port
   char inByte = Serial.read(); // read a byte
   delay(10); // *** added to make it work ***
   if (inByte == '*') { // if that byte is the desired character
   int len = 5; // expected string is 6 bytes long
   char inString[len]; // declare string variable
   for (int i = 0; i < len; i++) {
   inString[i] = Serial.read();
 }
    if ( strstr(inString, "reset") != NULL ) 
    {
     reset(); 
    }
   
   if ( strstr(inString, "fast") != NULL )
    {
     fast(); 
    }

if ( strstr(inString, "slow") != NULL ) 
    {
     slow(); 
    }


   }

that works with commands , what you want to do is turn instring into a int.
You need use itoa`s mate , itoa converts a int to a string.

it`s on the <stdlib.h> library

http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#g3a1fe00c1327bbabc76688a7a1d73370

atoi ()

I need to get the arduino to respond to specific input over serial from a terminal window.

In the terminal window, I'll be typing a 1 - 4 digit number, followed by a carriage return.

Ultimately I'd like this four digit number saved as an Int on the arduino.

Look at the MRMP. It does this in a way that is general purpose and may fit your plans...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1232140631