参考:https://liefyuan.blog.csdn.net/article/details/78636355
一.接线
OLED | Arduino Uno |
---|---|
VCC | 3.3v或5v |
GND | GND |
SCL | A5 |
SDA | A4 |
二.取模
百度下载一个取模软件:PCtoLCD2002完美版
1.进行设置
2.设置好之后,输入汉字,生成字模
三.写程序
#include "U8glib.h"
#include "clib/u8g.h"
//接线:四针oled,Vcc-3.3v或5v,GND-GND,SCL-A5,SDA-A4
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
//我
const uint8_t bitmap_wo [] U8G_PROGMEM ={
0x04,0x40,0x0E,0x50,0x78,0x48,0x08,0x48,0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x44,
0x0A,0x44,0x0C,0x48,0x18,0x30,0x68,0x22,0x08,0x52,0x08,0x8A,0x2B,0x06,0x10,0x02
};
//真
const uint8_t bitmap_zhen [] U8G_PROGMEM ={
0x01,0x00,0x01,0x00,0x7F,0xFC,0x01,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,
0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0xFF,0xFE,0x08,0x20,0x10,0x10,0x20,0x08
};
//棒
const uint8_t bitmap_bang [] U8G_PROGMEM ={
0x10,0x20,0x10,0x20,0x13,0xFE,0x10,0x20,0xFD,0xFC,0x10,0x40,0x33,0xFE,0x38,0x88,
0x55,0x24,0x52,0x22,0x90,0xF8,0x10,0x20,0x13,0xFE,0x10,0x20,0x10,0x20,0x10,0x20
};
/*参数解释:drawBitmapP(u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
x:位图左上角的横坐标
y:位图左上角的纵坐标
cnt:在水平方向上的位图的字节数。该位图的宽度是cnt* 8(1字节=8位)
h:位图的高
*bitmap:位图对象
*/
void draw(void) {
u8g.setColorIndex(1);
u8g.drawBitmapP ( 0 , 0 , 2 , 16 , bitmap_wo);
u8g.drawBitmapP ( 17 , 0 , 2 , 16 , bitmap_zhen);
u8g.drawBitmapP ( 34 , 0 , 2 , 16 , bitmap_bang);
}
void setup() {
}
void loop() {
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
}
接好线,编译,上传。