I already use string to declare pesan instead use char. but after i compile the program.it say that string isn't data type.
And it's right. A string is a NULL terminated array of chars, not a separate type.
When I use String to declare pesan, after compile the program, there is an error. it say invalid convertion from int to const char.
And it's right. You can't assign an int (what you get from Serial.read()) to a String.
There are dozens of examples of how to read serial data (one character at a time), and store them in an array. Hey, look, here's one:
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
void setup()
{
Serial.begin(57600);
// Other stuff...
}
void loop()
{
// Read all serial data available, as fast as possible
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
Your sender should be delimiting the stuff you are trying to parse in some way that makes it easy for you to read.