如何解决“对'11'中的成员'read'的请求,这是非类类型'int'的请求”错误

时间:2019-07-05 06:15:51

标签: arduino-uno adafruit

我正在尝试使用dht11温湿度传感器来测量温度和湿度。

我正在使用adafruit的dht11库和示例代码,但是当我尝试查看校验和时,出现此错误:

Arduino: 1.8.9 (Windows 8.1), Board: "Arduino/Genuino Uno

C:\Users\K52J\Documents\Arduino\DHTtester\DHTtester.ino: In function 'void loop()':
DHTtester:44:19: error: request for member 'read' in '11', which is of non-class type 'int'
int chk = DHT11.read(DHTPIN);
               ^

exit status 1
request for member 'read' in '11', which is of non-class type 'int'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

我是新手,无法解决问题。

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib:     https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"
#include <Adafruit_Sensor.h>

#define DHTPIN 2     // Digital pin connected to the DHT sensor

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)


// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(1000);

  int chk = DHT11.read(DHTPIN);
  Serial.println(chk);

... }

0 个答案:

没有答案