Arduino:1.8.19 (Windows 10), 开发板:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)" C:\Users\Administrator\Desktop\___\___.ino: In function 'void loop()': ___:28:11: error: 'hour' was not declared in this scope int H = hour(); ^~~~ ___:29:11: error: 'minute' was not declared in this scope int M = minute(); ^~~~~~ C:\Users\Administrator\Desktop\___\___.ino:29:11: note: suggested alternative: 'init' int M = minute(); ^~~~~~ init ___:32:21: error: 'curHour' was not declared in this scope String timeStr = (curHour < 10 ? "0" : "") + String(curHour) + ":" + (curMinute < 10 ? "0" : "") + String(curMinute); ^~~~~~~ ___:32:73: error: 'curMinute' was not declared in this scope String timeStr = (curHour < 10 ? "0" : "") + String(curHour) + ":" + (curMinute < 10 ? "0" : "") + String(curMinute); ^~~~~~~~~ exit status 1 'hour' was not declared in this scope 在文件 -> 首选项开启 “编译过程中显示详细输出”选项 这份报告会包含更多信息。
时间: 2024-01-21 22:02:44 浏览: 209
Arduino Mega2560—采用USB接口、具有多达54路数字输入输出的开发板-电路方案
这个错误提示是因为编译器无法识别hour、minute、curHour和curMinute变量,因为它们没有被声明或定义。你需要在函数外部定义这些变量,例如:
```
int hour;
int minute;
int curHour;
int curMinute;
void setup() {
// ...
}
void loop() {
hour = hour();
minute = minute();
// Do something with hour and minute variables
curHour = 12;
curMinute = 30;
String timeStr = (curHour < 10 ? "0" : "") + String(curHour) + ":" + (curMinute < 10 ? "0" : "") + String(curMinute);
// ...
}
```
这样就可以解决这个问题了。
阅读全文