• 大小: 15KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-18
  • 语言: 其他
  • 标签: arduino  

资源简介

dht11 库文件 欢迎下载

资源截图

代码片段和文件信息

/* DHT library

MIT license
written by Adafruit Industries
*/

#include “DHT.h“

#define MIN_INTERVAL 2000
#define TIMEOUT -1

DHT::DHT(uint8_t pin uint8_t type uint8_t count) {
  _pin = pin;
  _type = type;
  #ifdef __AVR
    _bit = digitalPinToBitMask(pin);
    _port = digitalPinToPort(pin);
  #endif
  _maxcycles = microsecondsToClockCycles(1000);  // 1 millisecond timeout for
                                                 // reading pulses from DHT sensor.
  // Note that count is now ignored as the DHT reading algorithm adjusts itself
  // based on the speed of the processor.
}

// Optionally pass pull-up time (in microseconds) before DHT reading starts.
// Default is 55 (see function declaration in DHT.h).
void DHT::begin(uint8_t usec) {
  // set up the pins!
  pinMode(_pin INPUT_PULLUP);
  // Using this value makes sure that millis() - lastreadtime will be
  // >= MIN_INTERVAL right away. Note that this assignment wraps around
  // but so will the subtraction.
  _lastreadtime = millis() - MIN_INTERVAL;
  DEBUG_PRINT(“DHT max clock cycles: “); DEBUG_PRINTLN(_maxcycles DEC);
  pullTime = usec;
}

//boolean S == Scale.  True == Fahrenheit; False == Celcius
float DHT::readTemperature(bool S bool force) {
  float f = NAN;

  if (read(force)) {
    switch (_type) {
    case DHT11:
      f = data[2];
      if (data[3] & 0x80) {
        f = -1 - f ;
      }
      f += (data[3] & 0x0f) * 0.1;
      if(S) {
        f = convertCtoF(f);
      }
      break;
    case DHT12:
      f = data[2];
      f += (data[3] & 0x0f) * 0.1;
      if (data[2] & 0x80) {
        f *= -1;
      }
      if(S) {
        f = convertCtoF(f);
      }
      break;
    case DHT22:
    case DHT21:
      f = ((word)(data[2] & 0x7F)) << 8 | data[3];
      f *= 0.1;
      if (data[2] & 0x80) {
        f *= -1;
      }
      if(S) {
        f = convertCtoF(f);
      }
      break;
    }
  }
  return f;
}

float DHT::convertCtoF(float c) {
  return c * 1.8 + 32;
}

float DHT::convertFtoC(float f) {
  return (f - 32) * 0.55555;
}

float DHT::readHumidity(bool force) {
  float f = NAN;
  if (read(force)) {
    switch (_type) {
    case DHT11:
    case DHT12:
      f = data[0] + data[1] * 0.1;
      break;
    case DHT22:
    case DHT21:
      f = ((word)data[0]) << 8 | data[1];
      f *= 0.1;
      break;
    }
  }
  return f;
}

//boolean isFahrenheit: True == Fahrenheit; False == Celcius
float DHT::computeHeatIndex(bool isFahrenheit) {
  float hi = computeHeatIndex(readTemperature(isFahrenheit) readHumidity()
    isFahrenheit);
  return isFahrenheit ? hi : convertFtoC(hi);
}

//boolean isFahrenheit: True == Fahrenheit; False == Celcius
float DHT::computeHeatIndex(float temperature float percentHumidity
  bool isFahrenheit) {
  // Using both Rothfusz and Steadman‘s equations
  // http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
  float hi;

  if (!isFahrenheit)
    temperature = convertCtoF(temperature);

  hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) *

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-02-18 18:20  DHT-sensor-library-master\
     目录           0  2019-02-18 18:20  DHT-sensor-library-master\.github\
     文件        2624  2019-02-18 18:20  DHT-sensor-library-master\.github\ISSUE_TEMPLATE.md
     文件        1415  2019-02-18 18:20  DHT-sensor-library-master\.github\PULL_REQUEST_TEMPLATE.md
     文件        9749  2019-02-18 18:20  DHT-sensor-library-master\DHT.cpp
     文件        1804  2019-02-18 18:20  DHT-sensor-library-master\DHT.h
     文件        6196  2019-02-18 18:20  DHT-sensor-library-master\DHT_U.cpp
     文件        2297  2019-02-18 18:20  DHT-sensor-library-master\DHT_U.h
     文件         942  2019-02-18 18:20  DHT-sensor-library-master\README.md
     目录           0  2019-02-18 18:20  DHT-sensor-library-master\examples\
     目录           0  2019-02-18 18:20  DHT-sensor-library-master\examples\DHT_Unified_Sensor\
     文件        3294  2019-02-18 18:20  DHT-sensor-library-master\examples\DHT_Unified_Sensor\DHT_Unified_Sensor.ino
     目录           0  2019-02-18 18:20  DHT-sensor-library-master\examples\DHTtester\
     文件        2539  2019-02-18 18:20  DHT-sensor-library-master\examples\DHTtester\DHTtester.ino
     文件         529  2019-02-18 18:20  DHT-sensor-library-master\keywords.txt
     文件         321  2019-02-18 18:20  DHT-sensor-library-master\library.properties

评论

共有 条评论