How to read a string value with a delimiter on Arduino?

后端 未结 7 943
小鲜肉
小鲜肉 2020-12-10 03:34

I have to manage servos from a computer.

So I have to send manage messages from computer to Arduino. I need manage the number of servo and the corner. I\'m thinking

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 04:02

    This code reads string until it sees '>' character

    void loop() {
      // put your main code here, to run repeatedly:
      String msg = getMessage();
    }
    
    String getMessage() {
      String msg = "";
    
      while (Serial.available()>0) {
        msg =  Serial.readStringUntil('>');
      }
      return msg;
    }
    

提交回复
热议问题