arduino - Serial.println 仅在 loop() 内部工作
问题描述
我的代码
void setup() {
Serial.begin(115200);
while (!Serial) {}
Serial.println("Setup");
}
int t = 0;
void loop() {
Serial.println("Loop1");
if (t==0){
t = 1;
Serial.println("Loop2");
}
}
打印的所有内容都是 Loop1(不确定地)。
编辑:按照@aMike 的建议添加了 !serial
任何的想法?
解决方案
在建立串行连接后添加一个短暂的延迟:
void setup() {
Serial.begin(115200);
while (!Serial);
delay(500); // this will ensure displaying your content on the serial monitor
Serial.println("Setup");
}
推荐阅读
- javascript - 如何使用节点 js 从 https 获取请求中获取请求正文
- python - python ipycytoscape通过id访问节点
- python - 复制表面并将其在屏幕上粘贴
- python - 如何使用时间序列和聚合值创建堆积条形图
- javascript - 在 GTM 中设置变量时 $(this).text() 的替代方案
- python - Python脚本在Ubuntu上失败但在Windows上工作
- mysql - 使触发器 where 子句依赖 3 个表?
- owl - 基于关系子集的 OWL 推理
- java - 默认情况下,如何使用 Spring JPA 为非主键提供自动递增值?
- google-sheets - 如何跟踪单元格中值随时间的变化。自引用挑战