#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define **16_GLCD_HEIGHT 16 //定义显示高度
#define **16_GLCD_WIDTH 16 //定义显示宽度
/*-- 文字: U --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_1[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,
0x66,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: N --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_2[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x00,0x63,0x00,0x73,0x00,0x7B,0x00,0x6F,0x00,
0x67,0x00,0x63,0x00,0x63,0x00,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: O --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_3[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,
0x66,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_4[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: R --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_5[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x7C,0x00,
0x6C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: 3 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_6[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x06,0x00,0x1C,0x00,
0x06,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: 试 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_7[] =
{
0x00,0x28,0x20,0x24,0x10,0x24,0x10,0x20,0x07,0xFE,0x00,0x20,0xF0,0x20,0x17,0xE0,
0x11,0x20,0x11,0x10,0x11,0x10,0x15,0x10,0x19,0xCA,0x17,0x0A,0x02,0x06,0x00,0x02
};
/*-- 文字: 用 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_8[] =
{
0x00,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,
0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x41,0x08,0x41,0x28,0x80,0x10
};
/*-- 文字: 感 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_10[] =
{
0x00,0x28,0x00,0x24,0x3F,0xFE,0x20,0x20,0x2F,0xA4,0x20,0x24,0x2F,0xA8,0x28,0x98,
0x28,0x92,0x4F,0xAA,0x40,0x46,0x80,0x82,0x01,0x00,0x48,0x84,0x48,0x12,0x87,0xF2
};
/*-- 文字: 谢 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_11[] =
{
0x01,0x08,0x42,0x08,0x27,0x88,0x24,0x88,0x07,0xBE,0x04,0x88,0xE7,0x88,0x24,0xC8,
0x24,0xA8,0x2F,0xA8,0x21,0x88,0x2A,0x88,0x34,0x88,0x28,0x88,0x02,0xA8,0x01,0x10
};
/*-- 文字: 2 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_12[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x06,0x00,0x0C,0x00,
0x18,0x00,0x30,0x00,0x60,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: 1 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_13[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x1C,0x00,0x7C,0x00,0x0C,0x00,0x0C,0x00,
0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: I --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_14[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,
0x18,0x00,0x18,0x00,0x18,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-- 文字: C --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
static const unsigned char PROGMEM str_15[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x60,0x00,0x60,0x00,
0x60,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
display.clearDisplay();
//英文字符显示
display.setTextSize(1); //设置字体大小
display.setTextColor(WHITE); //设置字体颜色白色
display.setCursor(0,0); //设置字体的起始位置
display.println("Hello, world!"); //输出字符并换行
display.setTextColor(BLACK, WHITE); // 设置字体黑色,字体背景白色
display.println("3.141592"); // 输出数字并换行
display.setTextSize(2); // 设置字体大小
display.setTextColor(WHITE); // 设置字体白色
display.print("0x"); // 输出字符
display.println(0xDEADBEEF, HEX); // 输出为ASCII编码的十六进制
//中文字符显示
display.drawBitmap( 0, 32, str_1, 16, 16, 1); // 在坐标X:0 Y:32的位置显示中文字
display.drawBitmap( 16, 32, str_2, 16, 16, 1);
display.drawBitmap( 32, 32, str_3, 16, 16, 1);
display.drawBitmap( 48, 32, str_4, 16, 16, 1);
display.drawBitmap( 64, 32, str_5, 16, 16, 1);
display.drawBitmap( 80, 32, str_6, 16, 16, 1);
display.drawBitmap( 96, 32, str_7, 16, 16, 1);
display.drawBitmap(112, 32, str_8, 16, 16, 1);
display.drawBitmap( 16, 48, str_10, 16, 16, 1);
display.drawBitmap( 32, 48, str_11, 16, 16, 1);
display.drawBitmap( 48, 48, str_12, 16, 16, 1);
display.drawBitmap( 64, 48, str_13, 16, 16, 1);
display.drawBitmap( 80, 48, str_14, 16, 16, 1);
display.drawBitmap( 96, 48, str_15, 16, 16, 1);
display.display(); // 把缓存的都显示
}
void loop() {
}
显示效果如下: