To send data:
int x = 12;
Serial.print(x);
This results in "12" arriving at the serial port, and being stored in the serial receive buffer.
To read the data:
while(Serial.available() > 0)
{
int inByte = Serial.read();
}
This will result in inByte being assigned the value '1' at one point, and the value '2' at another point.
If you set up an array, and store each value read into that array, you could recreate the value 12.
char inData[10];
int index = 0;
while(Serial.available() > 0)
{
int inByte = Serial.read();
if(index < 10)
{
inData[index++] = inByte;
inData[index] = '\0'; // Terminating NULL
}
}
// At this point, inData MIGHT contain a whole packet...
To ensure that inData contains a whole packet, and end-of-packet marker needs to be sent. The carriage return/line feed added by Serial.println() are sufficient. Then, read data in the while loop, until the end-of-packet marker arrives. Then, you can parse it and reset stuff.