很喜欢捣鼓一些小东西,平时闲着就建模、打印、编程……
这次,我带来了我能随身带的温湿度检测盒子,看看帅帅的它吧!
代码
#include <U8g2lib.h>
#include <Wire.h>
#include <DHT.h>
#include "bitmap1.h"
#include "bitmap2.h"
#include "bitmap6.h"
#include "bitmap7.h"
#include "bitmap3.h"
#include "bitmap4.h"
#include "bitmap5.h"
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
//字体:宋体 字号:16px 显示文字:温度:
/*
----------------------------------------------------------------------
| 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
----------------------------------------------------------------------
*/
//字体:宋体 字号:16px 显示文字:℃
/*
----------------------------------------------------------------
| 0 0 |
|0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 |
| 0 0 0 0 0 |
| 0 0 |
| 0 0 |
| 0 0 |
| 0 0 |
| 0 0 |
| 0 0 |
| 0 0 |
| 0 |
| 0 0 0 |
| 0 0 0 |
| 0 0 0 0 0 |
| |
----------------------------------------------------------------
*/
//字体:宋体 字号:16px 显示文字:湿度:
/*
----------------------------------------------------------------------
| 0 |
| 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
----------------------------------------------------------------------
*/
//字体:宋体 字号:16px 显示文字:%rh
/*
--------------------------------------------------------------------------------------------------------------------------------
| |
| 0 0 0 |
| 0 0 0 |
| 0 0 0 0 0 |
| 0 0 0 0 |
| 0 0 0 0 |
| 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 |
| |
--------------------------------------------------------------------------------------------------------------------------------
*/
//字体:宋体 字号:16px 显示文字:好热啊
/*
------------------------------------------------------------------------------------------------
| 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 |
------------------------------------------------------------------------------------------------
*/
//字体:宋体 字号:16px 显示文字:好舒服
/*
------------------------------------------------------------------------------------------------
| 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 |
------------------------------------------------------------------------------------------------
*/
//字体:宋体 字号:16px 显示文字:好冷哦
/*
------------------------------------------------------------------------------------------------
| 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
|0 0 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 |
------------------------------------------------------------------------------------------------
*/
DHT dhtA0(A0, 11);
void page1() {
u8g2.drawXBMP(3, 25, 35, 16, bitmap1);
u8g2.drawXBMP(92, 25, 32, 16, bitmap2);
u8g2.drawXBMP(3, 45, 35, 16, bitmap6);
u8g2.drawXBMP(92, 45, 64, 16, bitmap7);
u8g2.setFont(u8g2_font_ncenR14_tf);
u8g2.setFontPosTop();
u8g2.setCursor(45,25);
u8g2.print(dhtA0.readTemperature());
u8g2.setCursor(45,45);
u8g2.print(dhtA0.readHumidity());
if (dhtA0.readTemperature() >= 30) {
u8g2.drawXBMP(40, 0, 48, 16, bitmap3);
} else if (dhtA0.readTemperature() >= 20 && dhtA0.readTemperature() < 30) {
u8g2.drawXBMP(40, 0, 48, 16, bitmap4);
} else {
u8g2.drawXBMP(40, 0, 48, 16, bitmap5);
}
}
void setup(){
u8g2.setI2CAddress(0x3C*2);
u8g2.begin();
dhtA0.begin();
u8g2.enableUTF8Print();
}
void loop(){
u8g2.firstPage();
do
{
page1();
}while(u8g2.nextPage());
delay(5000);
u8g2.clearDisplay();
}
伦**2024.03.20
666