问题
So my arduino is receiving a string from serial, comprising of three values separated by commas, I'm trying to separate these values into three different variables, the rest I can do.
The string looks something like this "1000,1.5,0.9" or "5000,20,0.01"
I would like something like: a - 1000, b - 1.5, c - 0.9
Cheers
回答1:
I presume you are receiving the string that can be split in to three parts. Here's a sample code taken from this thread:
void setup(){
Serial.begin(9600);
}
void loop(){
String first = Serial.readStringUntil(',');
Serial.read(); //next character is comma, so skip it using this
String second = Serial.readStringUntil(',');
Serial.read();
String third = Serial.readStringUntil('\0');
//parse your data here. example:
//double x = Double.parseDouble(first);
}
来源:https://stackoverflow.com/questions/29504679/splitting-a-comma-separated-string-through-serial-arduino