小编naw*_*was的帖子

为什么串行值与未发送的值一起打印两次?

使用下面的代码,我试图打印通过 Arduino 串行接收的值。但是该值会打印两次。打印值之一始终为 0。

byte b;
int i;

void setup() {
  Serial.begin(115200);
  Serial.setTimeout(10);
}

void loop() {
  while(Serial.available() == 0) {}
  i = Serial.parseInt();
  Serial.println(i);
}

EXAMPLE: value sent is 15
Serial monitor output: 15
                       0

EXAMPLE: value sent is 99
Serial monitor output: 99
                       0
Run Code Online (Sandbox Code Playgroud)

serial-port arduino

2
推荐指数
1
解决办法
936
查看次数

标签 统计

arduino ×1

serial-port ×1