2021-07-14

#include <Arduino.h>
#include <U8g2lib.h>#include <Wire.h>#include "DHT.h"#define DHTPIN  2#define DHTTYPE DHT11//iic驱动方式U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);DHT dht(DHTPIN, DHTTYPE);void setup() {  u8g2.begin();  dht.begin();}char h_str[3];char t_str[3];float h;float t;void loop() {  h = dht.readHumidity();//读湿度  t = dht.readTemperature();//读温度(摄氏度)  strcpy(h_str, u8x8_u8toa(h, 2));    /* convert m to a string with two digits */  strcpy(t_str, u8x8_u8toa(t, 2));    /* convert m to a string with two digits */  u8g2.firstPage();  do {    u8g2.setFont(u8g2_font_fur20_tf);    u8g2.drawStr(0, 23, "T");    u8g2.drawStr(20, 23, ":");    u8g2.drawStr(40, 23, t_str);    u8g2.drawStr(90, 23, "C");    u8g2.drawStr(0, 63, "H");    u8g2.drawStr(20, 63, ":");    u8g2.drawStr(40, 63, h_str);    u8g2.drawStr(90, 63, "%");  } while ( u8g2.nextPage() );  delay(1000);}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值