阿里云IoT套件 SmartLight编译错误

2020-10-112548
AI 快速预览详细 收起
本文解决了在Arduino Uno开发板上编译SmartLight项目时遇到的'D2'未声明的编译错误。通过检查引脚定义并修正为正确的引脚编号(如'A2'),可以解决该问题。文章提供了详细的步骤和建议,帮助用户快速定位并修复错误,节省调试时间。

请问编译错误,啥原因?
Arduino:1.8.13 (Windows 10), 开发板:"Arduino Uno"



\arduino_modified_sketch_327840\SmartLight.ino: In function 'void openLight()':

SmartLight:6:24: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:34:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, HIGH);

                ^~~~~~~~~~~~~

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:6:24: note: suggested alternative: 'A2'

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:34:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, HIGH);

                ^~~~~~~~~~~~~

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino: In function 'void closeLight()':

SmartLight:6:24: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:38:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, LOW);

                ^~~~~~~~~~~~~

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:6:24: note: suggested alternative: 'A2'

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:38:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, LOW);

                ^~~~~~~~~~~~~

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino: In function 'void setup()':

SmartLight:6:24: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:98:11: note: in expansion of macro 'BEDROOD_LIGHT'

   pinMode(BEDROOD_LIGHT,OUTPUT);

           ^~~~~~~~~~~~~

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:6:24: note: suggested alternative: 'A2'

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\362663\AppData\Local\Temp\arduino_modified_sketch_327840\SmartLight.ino:98:11: note: in expansion of macro 'BEDROOD_LIGHT'

   pinMode(BEDROOD_LIGHT,OUTPUT);

           ^~~~~~~~~~~~~

exit status 1

'D2' was not declared in this scope



在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。


创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(2)
DFSH_Faith
DFSH_Faith
使用的SmartLight, 用的不是UNO板把? 或者用了OBLOQ?
如果是UNO那么改D2为13. 板载灯。
如果是其他板子,需要选择对板子的型号。 然后根据管脚映射来改代码中的管脚定义。
teu
teu
可问df技术:2124609059(qq)或者问@DFSH_Faith
- 没有更多了 -