|
OLED用的SH1106驱动,驱动库是U8glib和dht11,板是ARDUINO-ZION
废话少说上代码,代码是在论坛上早的,自已修改了下
u8g没有中文字,每个字型都是固定大小的,官网有图:
https://code.google.com/p/u8glib/wiki/fontsize
https://code.google.com/p/u8glib/wiki/userreference#getFontAscent这个地址是改字体的。。。
------------------------------------------------------------------------------------------------
#include <dht11.h>
#include <U8glib.h>
dht11 DHT11;
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);//A4、A5分别是SDA=A4和SCL=A5,OLEDSH1106驱动
//U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8);
#define DHT11PIN 23
void draw(void)
{
u8g.setFont(u8g_font_gdr25);//字体设置
//u8g.setPrintPos(15, 10);
//u8g.print(" Guo&Ping");
//u8g.print(" temp-humi");
//u8g.setPrintPos(40, 30);
u8g.setPrintPos(20, 30);
int chk = DHT11.read(DHT11PIN);
delay(100);
u8g.print((float)DHT11.temperature, 1);
u8g.setPrintPos(100, 30);
u8g.print("C");
delay(5);
u8g.setPrintPos(20, 58);
u8g.print((float)DHT11.humidity, 1);
u8g.setPrintPos(100, 58);
u8g.print("%");
delay(200);
}
void setup(void){
}
void loop(void) {
u8g.firstPage();
do {
draw();
long x = random(0,127);
long y = random(51,63);
}
while( u8g.nextPage() );
delay(50);
}
--------------------------------------------------------------------------
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|