1

我的主要 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 教程进行操作......

4

1 回答 1

1

原来这是某种缓存错误 - 删除 Arduino Build 文件夹将其整理出来

于 2013-06-29T14:06:25.323 回答