其他分享
首页 > 其他分享> > OLED液晶屏幕(3)串口读取文字

OLED液晶屏幕(3)串口读取文字

作者:互联网

 

 

 https://blog.csdn.net/iracer/article/details/50334041

String comdata = "";
 
void setup() {
  Serial.begin(9600);
  while(Serial.read()>= 0){} //clear serialbuffer
}
 
void loop() {
  // read data from serial port
  if(Serial.available()>0){
      delay(100);
      comdata = Serial.readString();
      Serial.print("Serial.readString:");
      Serial.println(comdata);
    }
    comdata = "";

}

  

Serial.readStringUntil();
说明
从串口缓存区读取字符到一个字符串型变量,直至读完或遇到某终止字符。

语法
Serial.readStringUntil(terminator)

参数
terminator:终止字符(cha型)

返回
从串口缓存区中读取的整个字符串,直至检测到终止字符。

String comdata = "";
char terminator = ',';
void setup() {
  Serial.begin(9600);
  while(Serial.read()>= 0){} //clear serialbuffer
}
 
void loop() {
  // read data from serial port
  if(Serial.available()>0){
      delay(100);
      comdata =Serial.readStringUntil(terminator);
     Serial.print("Serial.readStringUntil: ");
      Serial.println(comdata);
    }
    while(Serial.read()>= 0){}
}

  

标签:read,readStringUntil,OLED,terminator,串口,comdata,Serial,液晶屏幕,void
来源: https://www.cnblogs.com/kekeoutlook/p/10812464.html