我在我的主要arduino文件中有这个代码:
#include <HIH4030.h>
HIH4030 humiditySensor(0);
float humidity;
void setup() {
Serial.begin(9600);
}
void loop() {
delay(1000);
humidity = humiditySensor.sensorRH();
}
这是我的HIH4030.h文件内容:
#ifndef HIH4030_h
#define HIH4030_h
#include "Arduino.h"
class HIH4030{
public:
HIH4030(int pin);
float ratioHumidity();
float sensorRH();
float trueSensorRH(float temperature);
private:
int _pin;
float sample;
float temperature;
};
#endif
//data sheet https://www.sparkfun.com/datasheets/Sensors/Weather/SEN-09569-HIH-4030-datasheet.pdf
这是我的HIH4030.cpp文件内容:
#include <HIH4030.h>
HIH4030::HIH4030(int pin)
{
_pin = pin;
}
/*
gives humidity as a ratio of VDD
*/
float HIH4030::ratioHumidity(){
//poll analogue in
return analogRead(_pin);
}
/*
gives humidity as a percentage - numbers taken from datasheet
*/
float HIH4030::sensorRH(){
//poll analogue in
sample = analogRead(_pin)*5; //multiply by 5 as sample is a decimal of Vdd
return (sample-0.958)/0.0307;
}
/*
gives humidity adjusted for temperature (in degrees C) - numbers taken from datasheet
*/
float HIH4030::trueSensorRH(float temperature){
float rh = sensorRH();
temperature = temperature*0.00216;
return rh/(1.0546 - temperature);
}
当我编译时,我收到此错误:
Gathering compilation infomation...
Compiling sketch...
Cleaning...
Creating /Users/user/Documents/Arduino_Build/QuantifiedGarden/QuantifiedGarden.cpp.o...
Creating /Users/user/Documents/Arduino_Build/QuantifiedGarden/QuantifiedGarden.elf...
/Users/user/Documents/Arduino_Build/QuantifiedGarden/QuantifiedGarden.cpp.o: In function `__static_initialization_and_destruction_0':
/Users/user/Documents/Arduino_Build/QuantifiedGarden/QuantifiedGarden.cpp:7: undefined reference to `HIH4030::HIH4030(int)'
/Users/user/Documents/Arduino_Build/QuantifiedGarden/QuantifiedGarden.cpp.o: In function `loop':
/Users/user/Documents/Arduino_Build/QuantifiedGarden/QuantifiedGarden.cpp:23: undefined reference to `HIH4030::sensorRH()'
[Stino - Error while compiling.]
我是arduino的新手,我正在使用Stino Sublime Text 2插件。我已经将我为不同平台编写的更复杂的温度传感器库转换为Arduino并且它工作得很好 - 我看不出这个与其他库之间有什么区别但我必须遗漏一些东西。
据我所知,我已经遵循了如何制作自定义类Arduino教程的信......
答案 0 :(得分:1)
原来是某种缓存错误 - 删除Arduino Build文件夹将其整理出来