Use char * instead of String in "String name={"abc", "def"}". Also you are missing the brackets [] in that line too.
It should be char * name[2] = {"abc", "def"}; now when you collects the chars from Serial.read(), you should store them in an empty buffer first and once you have your string, add a NULL character ( '\0' ) at the end .
If you receive 3 characters from Serial.read() (buffer[0] = 'a', buffer[1] = 'b', buffer[2] = 'c') then the forth index ( buffer[3]) must be set to NULL or '\0'
Once you have done these above, and you were able to get your sent data, now you can use strcmp() to compare them.
Example:
if( !strcmp(buffer, "abc") ) // if they are the same, then this IF statement will be true.
{
// The strings match, do something here
}
Not sure what your code is supposed to do, but below is some very simple serial capture and compare code.
// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later
int ledPin = 13;
String readString;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Serial.println("serial on/off test 0021"); // so I can keep track
}
void loop() {
while (Serial.available()) {
delay(3);
char c = Serial.read();
readString += c;
}
if (readString.length() >0) {
Serial.println(readString);
if (readString == "on")
{
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
}
if (readString == "off")
{
digitalWrite(ledPin, LOW);
Serial.println("LED OFF");
}
readString="";
}
}
Yeah, but my serial monitor is running continuously through the loop displaying characters "MEAS:DC?" and "*TST?". The thing I did, I just compared bytes of the characters displayed on serial monitor and compared to min and max val of byte I should get. It works great not really as I expected to but ok. Thanks a lot I will save your sketch as the same.