门户网站建设工作汇报,长沙seo排名外包,平面设计去哪里学比较好,如何申请域名做网站0、结果
说明#xff1a;先来看看拍摄的显示结果#xff0c;如果是你想要的#xff0c;可以接着往下看。
1、外观
说明#xff1a;本次使用的oled是0.96寸的#xff0c;别的规格的屏幕不一定适用本教程#xff0c;一般而言有显示白色、蓝色和蓝黄一起显示的#xff0…0、结果
说明先来看看拍摄的显示结果如果是你想要的可以接着往下看。
1、外观
说明本次使用的oled是0.96寸的别的规格的屏幕不一定适用本教程一般而言有显示白色、蓝色和蓝黄一起显示的虽然dht11温湿度模块形态各异但是代码都是适用的因为它们的模块都是一样的。 2、连线
说明只需要连接三根线。
uno————dht11 5V--------------VCC GND--------------GND D7--------------DATA
说明只需要连接四根线。
uno————oled 0.96 5V--------------VCC GND--------------GND SCL--------------SCL SDA--------------SDA
3、源程序
说明采用非阻塞方式编写一定时间检测和显示一次温湿度数据并将对应功能进行函数化方便移植。
/****************************************dht11 part****************************************/
#include dht11.h //include library
#define dht11Pin 7 //Define DHT11 sensor connection pins
#define dht11TimeInterval 1000 //Detect the time interval of a tripdht11 DHT11; //Instantiate an object
unsigned long dht11Times 0; //Record the device running time
int dhtTemp 0, dht11Humi 0; //Storage temperature //Storage humidity
/****************************************oled96 part****************************************/
#include Arduino.h //include library
#include U8g2lib.h //include library
#include Wire.h //include libraryU8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset*/ U8X8_PIN_NONE);#define oledTimeInterval 1000 //Detect the time interval of a trip
unsigned long oledTimes 0; // Record the device running time/****************************************set up and loop part*********************************/
void setup() {u8g2.begin(); //Example Initialize the IIC
}
void loop() {getTempData(); //Obtain the temperature and humidity valuesoledDisplayMath(); //Display math
}
/****************************************oled96 part****************************************/
/*Display math*/
void oledDisplayMath() {if (millis() - oledTimes oledTimeInterval) { //This command is executed once in a whileoledTimes millis();u8g2.setFont(u8g2_font_ncenB14_tr); //u8g2_font_6x12_tru8g2.setFontDirection(0);u8g2.firstPage();do {u8g2.setCursor(0, 15); //0 means start at the first column and 15 means end at row 15u8g2.print(Temp:);u8g2.setCursor(64, 15); //0 means start at the first column and 15 means end at row 15u8g2.print(dhtTemp);u8g2.setCursor(96, 15); //0 means start at the first column and 15 means end at row 15u8g2.print( C);u8g2.setCursor(0, 31); //0 means start at the first column and 15 means end at row 15u8g2.print(Humi: );u8g2.setCursor(64, 31);u8g2.print(dht11Humi);u8g2.setCursor(96, 31); //0 means start at the first column and 15 means end at row 15u8g2.print( %);} while ( u8g2.nextPage() );}
}
/****************************************dht11 part****************************************/
/*Obtain the temperature and humidity values*/
void getTempData() {if (millis() - dht11Times dht11TimeInterval) {dht11Times millis();DHT11.read(dht11Pin); //Update all sensor informationdhtTemp DHT11.temperature;dht11Humi DHT11.humidity;Serial.print(Temperature: );Serial.print(dhtTemp);Serial.print( (C), );Serial.print(Humidity: );Serial.print(dht11Humi);Serial.println( (%).);}
}
4、注意事项
说明需要在线下载u8glib.h库文件和dht11.h库文件。 文章转载自: http://www.morning.yrflh.cn.gov.cn.yrflh.cn http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.rwmq.cn.gov.cn.rwmq.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.tbkqs.cn.gov.cn.tbkqs.cn http://www.morning.jyzqn.cn.gov.cn.jyzqn.cn http://www.morning.rsjng.cn.gov.cn.rsjng.cn http://www.morning.qbdsx.cn.gov.cn.qbdsx.cn http://www.morning.krgjc.cn.gov.cn.krgjc.cn http://www.morning.ktrzt.cn.gov.cn.ktrzt.cn http://www.morning.bpxmw.cn.gov.cn.bpxmw.cn http://www.morning.tjsxx.cn.gov.cn.tjsxx.cn http://www.morning.ccyns.cn.gov.cn.ccyns.cn http://www.morning.nnpfz.cn.gov.cn.nnpfz.cn http://www.morning.mjqms.cn.gov.cn.mjqms.cn http://www.morning.zwckz.cn.gov.cn.zwckz.cn http://www.morning.ppghc.cn.gov.cn.ppghc.cn http://www.morning.phlwj.cn.gov.cn.phlwj.cn http://www.morning.xcbnc.cn.gov.cn.xcbnc.cn http://www.morning.wljzr.cn.gov.cn.wljzr.cn http://www.morning.yfrlk.cn.gov.cn.yfrlk.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.cbchz.cn.gov.cn.cbchz.cn http://www.morning.stbhn.cn.gov.cn.stbhn.cn http://www.morning.nggbf.cn.gov.cn.nggbf.cn http://www.morning.pdmc.cn.gov.cn.pdmc.cn http://www.morning.xhqr.cn.gov.cn.xhqr.cn http://www.morning.gtcym.cn.gov.cn.gtcym.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.rtzd.cn.gov.cn.rtzd.cn http://www.morning.lmjtp.cn.gov.cn.lmjtp.cn http://www.morning.zxcny.cn.gov.cn.zxcny.cn http://www.morning.ypxyl.cn.gov.cn.ypxyl.cn http://www.morning.rxyz.cn.gov.cn.rxyz.cn http://www.morning.hsdhr.cn.gov.cn.hsdhr.cn http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn http://www.morning.mjctt.cn.gov.cn.mjctt.cn http://www.morning.zxwqt.cn.gov.cn.zxwqt.cn http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.rqxtb.cn.gov.cn.rqxtb.cn http://www.morning.tkyry.cn.gov.cn.tkyry.cn http://www.morning.jbmbj.cn.gov.cn.jbmbj.cn http://www.morning.kehejia.com.gov.cn.kehejia.com http://www.morning.phzrq.cn.gov.cn.phzrq.cn http://www.morning.zpyh.cn.gov.cn.zpyh.cn http://www.morning.dljujia.com.gov.cn.dljujia.com http://www.morning.dycbp.cn.gov.cn.dycbp.cn http://www.morning.ymfzd.cn.gov.cn.ymfzd.cn http://www.morning.lbbrw.cn.gov.cn.lbbrw.cn http://www.morning.rrxnz.cn.gov.cn.rrxnz.cn http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.hdqqr.cn.gov.cn.hdqqr.cn http://www.morning.ghphp.cn.gov.cn.ghphp.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.rqhbt.cn.gov.cn.rqhbt.cn http://www.morning.caswellintl.com.gov.cn.caswellintl.com http://www.morning.mnjyf.cn.gov.cn.mnjyf.cn http://www.morning.sjsfw.cn.gov.cn.sjsfw.cn http://www.morning.kbntl.cn.gov.cn.kbntl.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.ltqtp.cn.gov.cn.ltqtp.cn http://www.morning.wnnlr.cn.gov.cn.wnnlr.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.yltyr.cn.gov.cn.yltyr.cn http://www.morning.jlboyuan.cn.gov.cn.jlboyuan.cn http://www.morning.wcrcy.cn.gov.cn.wcrcy.cn http://www.morning.wgkz.cn.gov.cn.wgkz.cn http://www.morning.qrmry.cn.gov.cn.qrmry.cn http://www.morning.rgsgk.cn.gov.cn.rgsgk.cn http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn http://www.morning.cwlxs.cn.gov.cn.cwlxs.cn http://www.morning.dhyqg.cn.gov.cn.dhyqg.cn http://www.morning.tlyms.cn.gov.cn.tlyms.cn http://www.morning.qbnfc.cn.gov.cn.qbnfc.cn http://www.morning.crkhd.cn.gov.cn.crkhd.cn http://www.morning.hdrsr.cn.gov.cn.hdrsr.cn http://www.morning.dyrzm.cn.gov.cn.dyrzm.cn