资源简介
DHT11库,官方库没下下来的可以用这个,用于单片机项目使用,温湿度模块,也是自己在用的,希望可以帮到你

代码片段和文件信息
//
// FILE: dht11.cpp
// VERSION: 0.4.1
// PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino
// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
//
// DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
//
// HISTORY:
// George Hadjikyriacou - Original version (??)
// Mod by SimKard - Version 0.2 (24/11/2010)
// Mod by Rob Tillaart - Version 0.3 (28/03/2011)
// + added comments
// + removed all non DHT11 specific code
// + added references
// Mod by Rob Tillaart - Version 0.4 (17/03/2012)
// + added 1.0 support
// Mod by Rob Tillaart - Version 0.4.1 (19/05/2012)
// + added error codes
//
#include “dht11.h“
// Return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht11::read(int pin)
{
// BUFFER TO RECEIVE
uint8_t bits[5];
uint8_t cnt = 7;
uint8_t idx = 0;
// EMPTY BUFFER
for (int i=0; i< 5; i++) bits[i] = 0;
// REQUEST SAMPLE
pinMode(pin OUTPUT);
digitalWrite(pin LOW);
delay(18);
digitalWrite(pin HIGH);
delayMicroseconds(40);
pinMode(pin INPUT);
// ACKNOWLEDGE or TIMEOUT
unsigned int loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
for (int i=0; i<40; i++)
{
loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
unsigned long t = micros();
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
if (cnt == 0) // next byte?
{
cnt = 7; // restart at MSB
idx++; // next byte!
}
else cnt--;
}
// WRITE TO RIGHT VARS
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
humidity = bits[0];
temperature = bits[2];
uint8_t sum = bits[0] + bits[2];
//if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
return DHTLIB_OK;
}
//
// END OF FILE
//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 524 2013-05-29 14:01 Dht11\Stino.settings
文件 2151 2013-05-29 14:04 Dht11\dht11.cpp
文件 408 2013-05-29 14:01 Dht11\dht11.h
目录 0 2013-05-02 22:16 Dht11\examples\
目录 0 2013-05-02 22:16 Dht11\examples\dht11\
文件 2474 2012-09-05 10:41 Dht11\examples\dht11\dht11.ino
目录 0 2013-05-29 13:58 Dht11\
- 上一篇:数据结构动画演示
- 下一篇:Verilog实现单周期十条指令的cpu
相关资源
- E4A无障碍跨程序操作类库(带源码、
- ADNS-3080光流传感器测试程序Arduino
- Microsoft基本类库 (MFC)(C 库)
- EESkill NRF24L01 无线模块用户手册
- E4A免ROOT截图截桌面图类库
- 清明_跨程序辅助类库 8+共享 e4a 易安
-
NModbus4 通讯类库(fr
amework4.5版本) - e4a跨程序清明辅助类库
- E4A悬浮窗类库、无障碍类库
- E4A BG_跨程序辅助类库+授权源码+悬浮
- Arduino nano 工程文件
- Arduino教程 Lesson 之--自制风扇
- 基于Arduino的智能环境监控系统设计
- 基于Arduino和Machtalk的温棚环境监测系
- arduino pca9685多舵机同时控制案例
- arduino技术内幕
- Arduino电子设计实战指南.零基础篇_超
- 物联网智能家居平台DIY:ARDUINO 物联网
- 实验1.zip arduino跑马灯led灯实验,串口
- opencat所有资料.zip
- arduino主机,stm8从机。I2C测试 。每次
- CImage 强大的图像处理类库
- DS18B20_Serial_println.ino
- 百度地图类库 聚合marker.zip
- 百度地图类库 拉框放大工具.zip
- 百度地图类库 自定义信息窗口.zip
- ps2手柄arduino库文件
- 基于手机蓝牙的arduino遥控小车
- arduino中的can库函数
- 密码+指纹锁资料包.rar
评论
共有 条评论