oled屏幕
oled
连接线路
Oled-Arduino:
GND-GND
VCC-3v3
SCL-A4
SDA-A5
案例
使用arduino控制oled屏幕循环轮播显示两种不同的“续加仪”字样。
库使用
需要使用到已有库Wire、Adafruit_GFX、Adafruit_SSD1306,可直接在arduino中搜素安装
基本的用法如下:
//引入IIC通讯所需的Wire库文件
#include
// 引入驱动OLED0.96所需的库
#include
#include
// 参数依次为:屏幕像素宽、高、Wire对象、重置引脚
Adafruit_SSD1306 display(128, 64, &Wire, 4);
// 初始化OLED并设置其IIC地址为 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//设置光标位置
//输出文字(西文);
display.print("hello Xujiayi!");
//显示
display.display();
自定义图形/文字输出:
static const unsigned char PROGMEM xu[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x01,0x00,0x1C,0x00,0x03,0x80,0x18,0x00,
0x03,0x00,0x18,0x60,0x02,0x07,0xFF,0xF0,0x06,0x00,0x18,0x00,0x04,0x20,0x18,0x00,
0x0C,0x38,0x18,0x00,0x08,0x70,0x18,0x08,0x10,0x6F,0xFF,0xFC,0x31,0xC0,0x08,0x1C,
0x3E,0x82,0x0E,0x30,0x11,0x81,0xCC,0x20,0x01,0x00,0xCC,0x00,0x02,0x00,0x4C,0x00,
0x06,0x06,0x0C,0x00,0x04,0x03,0x8C,0x00,0x08,0xF1,0x8C,0x00,0x1F,0x01,0x08,0x18,
0x18,0x1F,0xFF,0xFC,0x00,0x00,0x08,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,
0x00,0xE0,0x37,0x00,0x1F,0x00,0x61,0xC0,0x38,0x00,0xC0,0x70,0x00,0x03,0x80,0x30,
0x00,0x0E,0x00,0x10,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"续",0*/
// 显示文字 (左上x坐标,右上y坐标, 图形数组, 图形像素点宽、高, 颜色)
display.drawBitmap(0, 0, xu, 32, 32, 1);
其中图形数组的获取方法见下文。
取模
使用pctolcd软件即可完成:
然后复制数据作为数组数据即可
实现
static const unsigned char PROGMEM xu[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x01,0x00,0x1C,0x00,0x03,0x80,0x18,0x00,
0x03,0x00,0x18,0x60,0x02,0x07,0xFF,0xF0,0x06,0x00,0x18,0x00,0x04,0x20,0x18,0x00,
0x0C,0x38,0x18,0x00,0x08,0x70,0x18,0x08,0x10,0x6F,0xFF,0xFC,0x31,0xC0,0x08,0x1C,
0x3E,0x82,0x0E,0x30,0x11,0x81,0xCC,0x20,0x01,0x00,0xCC,0x00,0x02,0x00,0x4C,0x00,
0x06,0x06,0x0C,0x00,0x04,0x03,0x8C,0x00,0x08,0xF1,0x8C,0x00,0x1F,0x01,0x08,0x18,
0x18,0x1F,0xFF,0xFC,0x00,0x00,0x08,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,
0x00,0xE0,0x37,0x00,0x1F,0x00,0x61,0xC0,0x38,0x00,0xC0,0x70,0x00,0x03,0x80,0x30,
0x00,0x0E,0x00,0x10,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"续",0*/
static const unsigned char PROGMEM jia[] = {
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,0x80,0x00,0x00,
0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x10,0x01,0x82,0x1F,0xF8,
0x3F,0xFF,0x10,0x18,0x01,0x83,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,
0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,
0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x02,0x10,0x18,0x01,0x02,0x10,0x18,
0x03,0x06,0x10,0x18,0x03,0x06,0x10,0x18,0x02,0x06,0x10,0x18,0x06,0x06,0x10,0x18,
0x04,0x06,0x10,0x18,0x0D,0x0C,0x1F,0xF8,0x08,0xFC,0x10,0x18,0x10,0x38,0x10,0x18,
0x20,0x10,0x10,0x18,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"加",1*/
static const unsigned char PROGMEM yi[] = {
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x70,0x80,0x00,0x00,0xE0,0x40,0x00,
0x00,0xC0,0x20,0x00,0x00,0xC0,0x30,0x00,0x01,0x80,0x38,0x40,0x01,0x80,0x18,0x60,
0x03,0x04,0x10,0xE0,0x03,0x04,0x00,0xC0,0x03,0x82,0x00,0x80,0x07,0x82,0x01,0x80,
0x0D,0x82,0x01,0x80,0x09,0x81,0x03,0x00,0x19,0x81,0x03,0x00,0x11,0x80,0x86,0x00,
0x21,0x80,0xC6,0x00,0x41,0x80,0x44,0x00,0x01,0x80,0x6C,0x00,0x01,0x80,0x28,0x00,
0x01,0x80,0x38,0x00,0x01,0x80,0x38,0x00,0x01,0x80,0x6C,0x00,0x01,0x80,0x46,0x00,
0x01,0x80,0x83,0x80,0x01,0x83,0x01,0xC0,0x01,0x86,0x00,0xF0,0x01,0x88,0x00,0x7E,
0x01,0xB0,0x00,0x30,0x01,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"仪",2*/
static const unsigned char PROGMEM xu1[] = {
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,0x38,0x00,
0x00,0x60,0x38,0x00,0x00,0xE3,0xFF,0xC0,0x01,0xE3,0xFF,0xC0,0x07,0x80,0x38,0x30,
0x0E,0x37,0xFF,0xF0,0x1C,0xF7,0x00,0x70,0x1F,0xE1,0xCC,0x30,0x11,0xC0,0xEE,0x10,
0x03,0x03,0x0C,0x10,0x06,0xF3,0xCC,0x10,0x0F,0xC0,0x2C,0x00,0x0E,0x07,0xFF,0xFE,
0x00,0x7F,0xFF,0xFE,0x07,0xE0,0x38,0x3C,0x3F,0x80,0x77,0x00,0x7E,0x01,0xE7,0x80,
0x38,0x3F,0xC1,0xC0,0x00,0x1E,0x00,0xE0,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"续",0*/
static const unsigned char PROGMEM jia1[] = {
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,0x18,0x00,0x00,
0x00,0x1C,0x00,0x00,0x03,0x18,0x00,0x00,0x07,0xF8,0x00,0x00,0x0F,0xFF,0x18,0x18,
0x00,0x3F,0xBF,0xF8,0x00,0x73,0xBF,0xF8,0x00,0x63,0xB8,0x38,0x00,0xE3,0x38,0x18,
0x00,0xC3,0x38,0x18,0x01,0xC3,0x38,0x18,0x03,0x87,0x38,0x18,0x03,0x86,0x38,0x38,
0x07,0x0E,0x3F,0xF8,0x1E,0x0E,0x1F,0xF8,0x3C,0x1C,0x00,0x00,0x78,0x78,0x00,0x00,
0x31,0xF8,0x00,0x00,0x01,0xE0,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};/*"加",1*/
static const unsigned char PROGMEM yi1[] = {
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,0xC0,0x00,
0x00,0x70,0xC3,0x00,0x03,0xE0,0xE3,0x80,0x7F,0xC0,0x63,0x80,0x7F,0x80,0x27,0x00,
0x7F,0x8E,0x07,0x00,0x33,0x8F,0x07,0x00,0x03,0x83,0xCE,0x00,0x03,0x81,0xEE,0x00,
0x03,0x80,0x7C,0x00,0x03,0x80,0x3C,0x00,0x03,0x80,0x3C,0x00,0x03,0x80,0x7F,0x00,
0x03,0x81,0xE7,0x80,0x03,0x87,0xC3,0xE0,0x03,0xFF,0x81,0xF8,0x03,0xBE,0x00,0xFF,
0x03,0x80,0x00,0xFE,0x03,0x80,0x00,0x7C,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"仪",2*/
//引入IIC通讯所需的Wire库文件
#include
// 引入驱动OLED0.96所需的库
#include
#include
// 参数依次为:屏幕像素宽、高、Wire对象、重置引脚
Adafruit_SSD1306 display(128, 64, &Wire, 4);
void setup()
{
// 初始化OLED并设置其IIC地址为 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
int pos_x = 0;
void loop()
{
if(pos_x<256){
// 显示之前清屏
display.clearDisplay();
showCon(pos_x++);
showCon(pos_x-128);
//显示图形
display.display();
}else if(pos_x<512){
// 显示之前清屏
display.clearDisplay();
showCon1(pos_x++-256);
showCon1(pos_x-256-128);
//显示图形
display.display();
}else
pos_x=0;
}
void showCon(int x)
{
display.drawBitmap(x, 16, xu, 32, 32, 1);
display.drawBitmap(x+32, 16, jia, 32, 32, 1);
display.drawBitmap(x+64, 16, yi, 32, 32, 1);
}
void showCon1(int x)
{
display.drawBitmap(x+0, 16, xu1, 32, 32, 1);
display.drawBitmap(x+32, 16, jia1, 32, 32, 1);
display.drawBitmap(x+64, 16, yi1, 32, 32, 1);
}
审核编辑:刘清
-
OLED屏幕
+关注
关注
3文章
206浏览量
27959 -
Arduino
+关注
关注
187文章
6456浏览量
186467 -
GND
+关注
关注
2文章
527浏览量
38616
原文标题:Arduino控制oled屏幕显示自定义字体文字
文章出处:【微信号:续加仪,微信公众号:续加仪】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
评论