arduino控制oled屏幕显示
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.setcursor(0, 0);
//输出文字(西文);
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);
}
涂抹导热硅脂之前有哪些注意事项呢?
新思科技推出全新Fusion QIK加速基于RISC-V处理器的SoC设计
曝NVIDIA下一代显卡延期至9月份的台北电脑展发布
一文详解变压器
FP6276电流模式同步升压DC-DC转换器
使用arduino控制oled屏幕循环轮播显示两种不同的字样
苹果又偷偷研发黑科技 可折叠iPhone
新iPad Pro OLED屏幕本周投入生产,预计4月发货
浩亭和Haug Group成功完成BMS电路板与电池的连接联合解决方案
UV胶点胶加工所用UV胶水的特点及优势分析
人工智能是怎样预测分子的气味的
探索不同的SAR ADC模拟输入架构
沃尔玛不满机器人雇员 机器人短期内无法替代人类
模拟提示:ADC抽取
电机又烧毁了?赶紧记住这六点
红辣椒国民大视界评测 入门级手机完全够用
苹果将可能会在春季发布会推出付费iPhone和iPad游戏订阅服务
比特币现金值得去投资吗
安卓12将于2021年下半年正式发布
工业控制DeviceNet通讯介绍及优势