i have a problem in separating the data send by the pc and assigned those data data in different variable here's my code..
char c[30];
String getValue(String data, char separator, int index);
void setup()
{
Serial.begin(9600);
}
void loop(){
if (Serial.available()){
c[30]=Serial.read();
delay(50);
Serial.println(c[30]);
delay(50);
String cpNum = getValue(c[30], ' ', 0);
String logTime = getValue(c[30],' ',1);
Serial.println(cpNum);
delay(5);
Serial.println(logTime);
}
}
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length()-1;
for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
here's my error
sketch_feb27a.ino: In function 'void loop()':
sketch_feb27a:16: error: invalid conversion from 'char' to 'const char*'
sketch_feb27a:16: error: initializing argument 1 of 'String::String(const char*)'
sketch_feb27a:17: error: invalid conversion from 'char' to 'const char*'
sketch_feb27a:17: error: initializing argument 1 of 'String::String(const char*)'
]
Moderator edit: code tags corrected (I hope) AWOL.