2021-04-24

 // oled中文显示dht11测量值
#include // DHT11数字传感器库 
dht11 DHT11; 
#define DHT11PIN 4 // Data链接数字针脚4

#include "U8glib.h" // OLED库 

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C 

#define word1W 16 //定义第一个汉字的宽度
#define word1H 16 //定义第一个汉字的高度
#define word2W 16 //定义第二个汉字的宽度
#define word2H 16 //定义第二个汉字的高度
#define word3W 16 //定义第三个汉字的宽度
#define word3H 16 //定义第三个汉字的高度
#define word4W 16 //定义第四个汉字的宽度
#define word4H 16 //定义第四个汉字的高度
#define word5W 16 //定义第五个汉字的宽度
#define word5H 16 //定义第五个汉字的高度

//第一个汉字的编码“温”
static unsigned char word1[] U8G_PROGMEM = {
0x00,0x00,0xC4,0x1F,0x48,0x10,0x48,0x10,0xC1,0x1F,0x42,0x10,0x42,0x10,0xC8,0x1F,
0x08,0x00,0xE4,0x3F,0x27,0x25,0x24,0x25,0x24,0x25,0x24,0x25,0xF4,0x7F,0x00,0x00};
//第二个汉字的编码“湿”
static unsigned char word2[] U8G_PROGMEM = {
0x00,0x00,0xE4,0x1F,0x28,0x10,0x28,0x10,0xE1,0x1F,0x22,0x10,0x22,0x10,0xE8,0x1F,
0x88,0x04,0x84,0x04,0x97,0x24,0xA4,0x14,0xC4,0x0C,0x84,0x04,0xF4,0x7F,0x00,0x00};
//第三个汉字的编码“度”
static unsigned char word3[] U8G_PROGMEM = {
0x80,0x00,0x00,0x01,0xFC,0x7F,0x44,0x04,0x44,0x04,0xFC,0x3F,0x44,0x04,0x44,0x04,
0xC4,0x07,0x04,0x00,0xF4,0x0F,0x24,0x08,0x42,0x04,0x82,0x03,0x61,0x0C,0x1C,0x70};
//第四个汉字的编码“监”
static unsigned char word4[] U8G_PROGMEM = {
0x20,0x02,0x24,0x02,0x24,0x3E,0x24,0x02,0x24,0x09,0x24,0x11,0xA4,0x10,0x20,0x00,
0x00,0x00,0xFC,0x1F,0x24,0x12,0x24,0x12,0x24,0x12,0x24,0x12,0xFF,0x7F,0x00,0x00};
//第五个汉字的编码“测”
static unsigned char word5[] U8G_PROGMEM = {
0x00,0x20,0xE4,0x23,0x28,0x22,0x28,0x2A,0xA1,0x2A,0xA2,0x2A,0xA2,0x2A,0xA8,0x2A,
0xA8,0x2A,0xA4,0x2A,0xA7,0x2A,0x84,0x20,0x44,0x21,0x44,0x22,0x24,0x28,0x10,0x10};

//绘画第一个汉字的子程序
void worddraw(void) {
 u8g.drawXBMP( 10, 0,word1W,word1H, word1);//x坐标10,y坐标0,宽度,高度,编码word1
 u8g.drawXBMP( 28, 0,word2W,word2H, word2);//x坐标28,y坐标0,宽度,高度,编码word2
 u8g.drawXBMP( 46, 0,word3W,word3H, word3);//x坐标46,y坐标0,宽度,高度,编码word3
 u8g.drawXBMP( 62, 0,word4W,word4H, word4);//x坐标62,y坐标0,宽度,高度,编码word4
 u8g.drawXBMP(80, 0,word5W,word5H, word5);//x坐标80,y坐标0,宽度,高度,编码word5
 u8g.drawXBMP(0, 30,word1W,word1H, word1);//x坐标0,y坐标30,宽度,高度,编码温
 u8g.drawXBMP( 28, 30,word3W,word3H, word3);//x坐标28,y坐标30,宽度,高度,编码度
 u8g.drawXBMP(0, 48,word2W,word2H, word2);//x坐标0,y坐标0,宽度,高度,编码湿
 u8g.drawXBMP( 28, 48,word3W,word3H, word3);//x坐标28,y坐标48,宽度,高度,编码度
}

void draw(void) {
       u8g.setFont(u8g_font_8x13);//设置字体和自号,目前测试字号有fub14,17,20,30,49n
       u8g.setPrintPos(48, 48); //显示的位置
       u8g.print((float)DHT11.humidity); 
      
       u8g.setFont(u8g_font_8x13);//设置字体和自号,目前测试字号有fub14,17,20,30,49n
       u8g.setPrintPos(48, 30); //显示的位置
       u8g.print((float)DHT11.temperature);
}

void setup() 

  

void loop() 
{
int chk = DHT11.read(DHT11PIN); 
u8g.firstPage();
 do {   
       worddraw();//调用绘画第一个汉字的子程序显示汉字
       draw(); 
       } 
while( u8g.nextPage() );
 delay(200);
}

你可能感兴趣的:(python)