当我选择没有以 arduino serial moniter 结尾的行时如何从 Arduino 读取字符串

How To Read String from Arduino when am selecting no line ending at arduino serial moniter

当我在 arduino 串行监视器上选择没有结束行时如何从 Arduino 读取字符串。

您通常使用行尾 (CR+LF) 来标识用户输入的结尾。在您的情况下,不清楚什么是行尾终止符。假设 '。' (句点)比你应该使用序列中的字符直到你到达行终止符。
这是一个示例代码:

#define EOL_TERMINATOR '.'

int inByte = 0;         // incoming serial byte
String cmdLine;

void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  cmdLine = "";
}

void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
    if (inByte != EOL_TERMINATOR)
      cmdLine.concat(inByte);
    else {
      userCommand(cmdLine);
      cmdLine = ""; //reset cmdLine for next command
    }
  }
}

void userCommand(String cmd) {
  Serial.println("User command '"+cmd+"'");
}