簡體   English   中英

如何在arduino庫中包含多個目錄

[英]How to include multiple directories in arduino library

我的arduino庫文件夾包含一個名為DHT_sensor_Library的庫。 在此文件夾中,我還有另一個名為DHT_U的文件夾。 在此文件夾中,我有DHT_U.ccp和DHT_U.h。

問題是當我在arduino IDE中包含DHT_U.h時:

#include "DHT_U.h"

該錯誤說:Tempreture_Humidity_Sensor:2:19:錯誤:DHT_U.h:沒有這樣的文件或目錄

compilation terminated.

exit status 1
DHT_U.h: No such file or directory

我已經嘗試過#include "DHT_U/DHT_U.h"#include "DHT_U\\DHT_U.h"#include ..\\DHT_U.h" 。這些都#include ..\\DHT_U.h"

這是我的代碼的片段:

#include "DHT.h"
#include "DHT_U.h"
#include "LiquidCrystal.h"
#include "DHT.h"

完整的代碼可以在這里顯示:

#include <DHT.h>
#include <DHT_U.h>

// include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"

// set the DHT Pin
#define DHTPIN 8

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  dht.begin();

  // Print a message to the LCD.
  lcd.print("Temp:  Humidity:");
}

void loop() {
  delay(500);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // read humidity
  float h = dht.readHumidity();
  //read temperature in Fahrenheit
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(f)) {
    lcd.print("ERROR");
    return;
  }

  lcd.print(f);
  lcd.setCursor(7,1);
  lcd.print(h);  
}

我該如何解決?

嘗試包括"/home/your_username/arduino/lib/foo.h"類的孔路徑。 您確定它是.h文件而不是.hpp嗎?

要考慮的一件事是,在使用#include方法時,需要格外小心。

如果DHT_U.h位於同一方向的.ino文件,你可以用這個包括它:

#include "DHT_U.h"

但是,如果使用Arduino IDE中的庫管理器安裝了庫,則應該執行以下操作:

#include <DHT_U.h>

如果這些都不起作用,請確保已正確安裝了磁帶庫。 您可以嘗試使用已安裝的庫通過Arduino IDE測試示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM