Aduino 문자열에서 아이디와 값을 매핑시키기 String to sscanf
관련링크
본문
String readString = "1:20,3:20,5:100,12:5"; int id1, id2, id3, id4; int pos1, pos2, pos3, pos4; int buf_len = readString.length() + 1; char buf[buf_len]; readString.toCharArray(buf, buf_len); int n = sscanf(buf, "%d:%d,%d:%d,%d:%d,%d:%d", &id1, &pos1, &id2, &pos2, &id3, &pos3, &id4, &pos4); Serial.print(F("n=")); Serial.println(n); Serial.print(F("id1=")); Serial.print(id1); Serial.print(F(", pos1=")); Serial.println(pos1); Serial.print(F("id2=")); Serial.print(id2); Serial.print(F(", pos2=")); Serial.println(pos2); Serial.print(F("id3=")); Serial.print(id3); Serial.print(F(", pos3=")); Serial.println(pos3); Serial.print(F("id4=")); Serial.print(id4); Serial.print(F(", pos4=")); Serial.println(pos4*1000);