char command[] = "a:+20,b:145,c:-20,d:+34,e:90,f:45, 1000";
bool parseCommand(char * c) {
Serial.print("Parsing ["); Serial.print(c); Serial.println("]");
char * commaPtr = strtok(c, ",");
while (commaPtr != nullptr) {
Serial.print("\tToken ["); Serial.print(commaPtr); Serial.print("] -> ");
char * colonPtr = strchr(commaPtr, ':');
if (colonPtr != nullptr) { // we have a label
*colonPtr = '\0';
Serial.print("Label is '"); Serial.print(commaPtr);
long v = strtol(colonPtr + 1, nullptr, 10); // no fancy error detection but could be done
Serial.print("' and value is "); Serial.println(v);
} else { // we don't have a label, it's a duration
long d = strtol(commaPtr, nullptr, 10); // no fancy error detection but could be done
Serial.print("duration is "); Serial.print(d);
}
commaPtr = strtok(nullptr, ","); // go to next token
}
}
void setup() {
Serial.begin(115200);
parseCommand(command);
}
void loop() {}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5