Arduinoシリアルデータは文字列を配列に分割します



Arduino Serial Data Split String Into Array

/* * This procedure is suitable for unclassified '111,426' style strings * After segmentation, numdata[0]=111,numdata[1]=426 * And numdata[0] and numdata[1] are integer numbers */ #define numdata_length 2 String comdata = '' int numdata[numdata_length] = {0} int flag = 0 void setup() { Serial.begin(9600) } void loop() { int j = 0 //Continuously check the serial port buffer in a loop, read the string one by one while (Serial.available() > 0) { comdata += char(Serial.read()) delay(2) flag = 1 } //If data is received, perform comdata analysis operation, otherwise do nothing if(flag == 1) { for(int i = 0 i