资源简介
libraries.zip
代码片段和文件信息
//
// 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
//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-09-05 10:45 Dht11\
文件 2149 2012-09-04 14:09 Dht11\dht11.cpp
文件 392 2012-09-04 14:38 Dht11\dht11.h
目录 0 2012-09-05 10:45 Dht11\examples\
目录 0 2012-09-05 10:45 Dht11\examples\dht11\
文件 2474 2012-09-05 10:41 Dht11\examples\dht11\dht11.ino
目录 0 2014-07-05 22:10 U8glib\
文件 6225 2014-07-05 22:10 U8glib\ChangeLog
文件 733 2014-07-05 22:10 U8glib\INSTALL.TXT
文件 2764 2014-07-05 22:10 U8glib\U8glib.cpp
文件 53814 2014-07-05 22:10 U8glib\U8glib.h
目录 0 2014-07-05 22:10 U8glib\examples\
目录 0 2014-07-05 22:10 U8glib\examples\A2Printer\
文件 3751 2014-07-05 22:10 U8glib\examples\A2Printer\A2Printer.ino
目录 0 2014-07-05 22:10 U8glib\examples\Bitmap\
文件 11286 2014-07-05 22:10 U8glib\examples\Bitmap\Bitmap.ino
目录 0 2014-07-05 22:10 U8glib\examples\Chess\
文件 12859 2014-07-05 22:10 U8glib\examples\Chess\Chess.ino
目录 0 2014-07-05 22:10 U8glib\examples\Color\
文件 12122 2014-07-05 22:10 U8glib\examples\Color\Color.ino
目录 0 2014-07-05 22:10 U8glib\examples\Console\
文件 13705 2014-07-05 22:10 U8glib\examples\Console\Console.ino
目录 0 2014-07-05 22:10 U8glib\examples\F\
文件 11594 2014-07-05 22:10 U8glib\examples\F\F.ino
目录 0 2014-07-05 22:10 U8glib\examples\FPS\
文件 18888 2014-07-05 22:10 U8glib\examples\FPS\FPS.ino
目录 0 2014-07-05 22:10 U8glib\examples\GraphicsTest\
文件 14687 2014-07-05 22:10 U8glib\examples\GraphicsTest\GraphicsTest.ino
目录 0 2014-07-05 22:10 U8glib\examples\HelloWorld\
文件 11867 2014-07-05 22:10 U8glib\examples\HelloWorld\HelloWorld.ino
目录 0 2014-07-05 22:10 U8glib\examples\Menu\
............此处省略127个文件信息
相关资源
- install.rar
- CUMCM-2019-Problem-A-Chinese.pdf
- rer.zip
- vue.js全套视频教程(共12章——百度链
- Scratch素材包11.zip
- 坦克大战游戏源码素材文档.zip
- DeepLearnToolbox-regression.zip
- 小米平板2刷机带双系统带root完美版
- p_mod11a2_lst.zip
- 1ACP11月5日_791.docx
- ekfukf.zip
- 几十个开源的STM32项目.zip
- 1f8ffe22d0d64dfaab315d91f23cc94e.doc
- VxWorks操作系统指南.pdf
- proxy_switchyomega-2.5.20-an+fx.rar
- 线报采集接码监控.rar
- .ppt
- SVPWMfaultmix.slx
- banksystem.zip
- 风云ddos.rar
- 所有手机密码解锁_以后就不用花钱去
- Elasticsearch实战完整书签.pdf
- ETAP安装.rar
-
liquiba
se-demo.zip - 网易云音乐器.zip
- 亚马逊采集规则.ljobx
- 111111shuangmenxianjiance.rar
- 《鲁棒控制》课堂笔记-3-H无穷控制理
- 20151125招商更新版.rar
- 变速齿轮2.2.zip
评论
共有 条评论