资源简介
DHT11 21 22库文件
代码片段和文件信息
/* DHT library
MIT license*/
#include “DHT.h“
DHT::DHT(uint8_t pin uint8_t type uint8_t count) {
_pin = pin;
_type = type;
_count = count;
firstreading = true;
}
void DHT::begin(void) {
// set up the pins!
pinMode(_pin INPUT);
digitalWrite(_pin HIGH);
_lastreadtime = 0;
}
//boolean S == Scale. True == Farenheit; False == Celcius
float DHT::readTemperature(bool S) {
float f;
if (read()) {
switch (_type) {
case DHT11:
f = data[2];
if(S)
f = convertCtoF(f);
return f;
case DHT22:
case DHT21:
f = data[2] & 0x7F;
f *= 256;
f += data[3];
f /= 10;
if (data[2] & 0x80)
f *= -1;
if(S)
f = convertCtoF(f);
return f;
}
}
return NAN;
}
float DHT::convertCtoF(float c) {
return c * 9 / 5 + 32;
}
float DHT::convertFtoC(float f) {
return (f - 32) * 5 / 9;
}
float DHT::readHumidity(void) {
float f;
if (read()) {
switch (_type) {
case DHT11:
f = data[0];
return f;
case DHT22:
case DHT21:
f = data[0];
f *= 256;
f += data[1];
f /= 10;
return f;
}
}
return NAN;
}
float DHT::computeHeatIndex(float tempFahrenheit float percentHumidity) {
// Adapted from equation at: https://github.com/adafruit/DHT-sensor-library/issues/9 and
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
return -42.379 +
2.04901523 * tempFahrenheit +
10.14333127 * percentHumidity +
-0.22475541 * tempFahrenheit*percentHumidity +
-0.00683783 * pow(tempFahrenheit 2) +
-0.05481717 * pow(percentHumidity 2) +
0.00122874 * pow(tempFahrenheit 2) * percentHumidity +
0.00085282 * tempFahrenheit*pow(percentHumidity 2) +
-0.00000199 * pow(tempFahrenheit 2) * pow(percentHumidity 2);
}
boolean DHT::read(void) {
uint8_t laststate = HIGH;
uint8_t counter = 0;
uint8_t j = 0 i;
unsigned long currenttime;
// Check if sensor was read less than two seconds ago and return early
// to use last reading.
currenttime = millis();
if (currenttime < _lastreadtime) {
// ie there was a rollover
_lastreadtime = 0;
}
if (!firstreading && ((currenttime - _lastreadtime) < 2000)) {
return true; // return last correct measurement
//delay(2000 - (currenttime - _lastreadtime));
}
firstreading = false;
/*
Serial.print(“Currtime: “); Serial.print(currenttime);
Serial.print(“ Lasttime: “); Serial.print(_lastreadtime);
*/
_lastreadtime = millis();
data[0] = data[1] = data[2] = data[3] = data[4] = 0;
// pull the pin high and wait 250 milliseconds
digitalWrite(_pin HIGH);
delay(250);
// now pull it low for ~20 milliseconds
pinMode(_pin OUTPUT);
digitalWrite(_pin LOW);
delay(20);
noInterrupts();
digitalWrite(_pin HIGH);
delayMicroseconds(40);
pinMode(_pin INPUT);
// read in timings
for ( i=0; i< MAXTIMINGS; i++) {
counter = 0;
while (
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\
文件 177 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\.gitignore
文件 3980 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\DHT.cpp
文件 735 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\DHT.h
目录 0 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\DHTtester\
文件 2262 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\DHTtester\DHTtester.ino
文件 18026 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\LICENSE
文件 138 2014-08-05 15:12 temperature-and-humidity-sensor-AM2301-master\README.md
- 上一篇:植物大战僵尸辅助、基址易语言源码
- 下一篇:宏病毒实验报告
相关资源
- 基于zigbee温湿度传输及控制带wifiAPP查
- stm32之传感器DHT11.zip
- DS18B20温度+DHT11湿度+LCD1602
- DHT11温湿度传感器项目代码.rar
- STM32F103C8T6+DHT11+SGP30+CH340+ADC
- STM32F103C8T6+DHT11+OLED
- 基于STM32的DHT11的温湿度采集GSM报警系
- cc2530-contiki读取DHT11并发送数据例程
- STM32温湿度传感器DHT11代码,通过串口
- 基于proteus 的 STM32 采集DHT11 仿真 +
- DTH11温湿度显示在IIC_OLED上,好用,自
- STM32F103C8T6-DHT11温湿度传感器.rar
- 基于FPGA的DHT11的温湿度数据采集
- SampleApp_dht11.zip
- STM32-UCOSIII实战-----RTC+DHT11+按键+LCD显示
- 基于STC89C52的温湿度检测
- DHT11温湿度传感器例程
- 数字温湿度传感器DHT11详解及例程利用
- STM32DHT11程序
- 里程表 STM32+霍尔传感器+EEPROM+LCD+DHT
- stm32f103+dht11温湿度传感器例程
- DHT11.rar
- 完整工程串口12、DHT11、BH1750、mh-z14
- 温湿度传感器DHT11资料+程序
- 乐鑫Esp8266驱动 ds18b20、dht11 温湿度传
- STM32F103C8T6按键调整参数断电保护,温
- CC2530+DHT11温湿度传感器+HC-SR04超声波传
- STM32F103+温湿度+光照强度+LN33无线网络
- 基于modbus的dht11温湿度采集
- 环境监测系统
评论
共有 条评论