gpt4 book ai didi

arduino-ide - 如何在 Arduino 中使用 Serial.println 在同一行中打印文本和变量的值

转载 作者:行者123 更新时间:2023-12-04 16:33:26 25 4
gpt4 key购买 nike

我有这个代码:

 Serial.print("x:");
Serial.print(x);
Serial.print(" y: ");
Serial.println(y);

并且工作正常。有一个输出示例:
x:41 y: 31

但我想知道是否有办法将这四个句子写成一个,例如:
Serial.println("x:"+x+" y:"+y);

返回错误:
invalid operands of types 'const char*' and 'const char [4]' to binary 'operator+'

任何的想法?。提前致谢。

最佳答案

当您需要将值的组合和这些值的描述显示为一个字符串以通过串行通信显示时,字符串连接非常有用。

 int sValor = analogRead(A5); 
String StrUno = "Valor Sensor N°5: ";
String StrDos = StrUno + sValor ;
Serial.println(StrDos);

我们可以连接多个值,用所有数据形成一个字符串,然后发送它。
这也可以用于 LCD 显示。

关于arduino-ide - 如何在 Arduino 中使用 Serial.println 在同一行中打印文本和变量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38983371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com