我最近一直在做一个项目,使用土壤电导率传感器(Decagon Devices的5TE传感器)和我的Arduino Uno。我已经准备好编码,并在 GitHub 上找到了此示例代码(当您向下滚动页面时,示例代码就在那里)。当尝试在最新版本的Arduino上运行它时,它给了我这些编译错误:
sketch_dec15a:7: error: expected initializer before 'void'
sketch_dec15a:4: error: 'SDISerial' does not name a type
sketch_dec15a:9: error: expected initializer before 'void'
sketch_dec15a.ino: In function 'void loop()':
sketch_dec15a:22: error: 'connection' was not declared in this scope
注意:我相信我正确安装了库,但不是 100% 确定...更像是 85%。
代码有什么问题,如何使其工作?
示例代码是错误的。查看编译错误。它说的第一件事是:
sketch_dec15a:7: error: expected initializer before 'void'
所以它的意思是,它发现了一些void
的东西,并期望首先看到别的东西。 void
在你的代码中只出现两次,所以我们不能走得太远。让我们看一下第一void
紧围绕它的代码:
char tmp_buffer[4];
char sensor_info[]
//initialize variables
void setup(){
connection.begin();
Serial.begin(9600);//so we can print to standard uart
//small delay to let the sensor do its startup stuff
delay(3000);//3 seconds should be more than enough
}
就在void setup(){
//initialize variables
之前.这只是一个评论,而不是代码,所以它不算数。再回顾一行,我们看到:
char sensor_info[]
那条线有问题。努力工作,看看你是否能弄清楚(检查其他行的"提示")。如果你想不通,答案就在下面(把鼠标放在上面看看):
<块引用类>它需要在末尾使用分号 ";" 来完成语句。因为缺少分号,所以它认为"void setup(){"是前面语句的一部分。
块引用类>