当前位置:网站首页>ESP8266-NodeMCU——使用U8g2库点亮OLED
ESP8266-NodeMCU——使用U8g2库点亮OLED
2022-07-20 21:18:00 【嵌入式创客工坊】
前言
U8g2是嵌入式设备的单色图形库,U8g2库提供了大量绘制函数,简单引用即可实现想要的效果,并且适用大部分屏幕驱动
一、软件准备
(1)Arduino IDE
(2)u8g2库文件:点击跳转(如果在IDE里不能下载就从这下载,解压后放去库路径里,如果不出意外,库路径都是在: 文档 / Arduino / libraries )
二、硬件准备
(1)ESP8266-NodeMCU
(2)1.3' OLED屏幕模块(7针,SSD1306驱动)
(3)一根可以传输数据的micro USB线
三、实现代码
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_1_4W_SW_SPI u8g2 (/*显示方向*/U8G2_R0, /*clock/SCL*/D1, /*data/SDA*/D2, /*cs(GND)*/U8X8_PIN_NONE ,/*DC*/D4 ,/*reset/RST*/D3);
int i;
void setup() {
u8g2.begin(); //显示器初始化
u8g2.enableUTF8Print();
}
void loop() {
i++;
if(i==100) i=0;
u8g2.firstPage(); //此为显示循环
while ( u8g2.nextPage( ) )
{
u8g2.drawFrame(9,25,103,15); //画空方框
u8g2.drawBox(12,27,i,11); //画实心方形
u8g2.setFont(u8g2_font_wqy14_t_gb2312a); //设置中文字体
u8g2.setCursor(20,20);u8g2.print("系统初始化");
u8g2.setFont(u8g2_font_ncenB10_tr); //设置字符串字体
u8g2.setCursor(54,54);u8g2.print(i);
u8g2.setFont(u8g2_font_ncenB10_tr); u8g2.drawStr(70,54,"%");
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawUTF8(90,20, "··· "); //设置特殊字体
}
}
四、实现效果
想深入了解U8G2库,推荐跳转:深入学习Arduino u8g2 OLED库,一篇就够
边栏推荐
- BGP (border gateway protocol) border gateway protocol
- Press the delete key in the gridcontrol of devaxpress to delete the selected line item
- 在竞争白热化的电商行业,链动2+1模式为什么还能生存那么久?
- Section 2 of Chapter 2: string index and slicing
- 04 提取最新的数据
- Lambda表达式
- Section 14 of Chapter 2: the concept of dictionary
- 第二章第三节:字符串常规操作
- Xshell determines that if the file exceeds the specified size, the file will be emptied
- C语言三大结构
猜你喜欢
随机推荐
2.3 分支语句
Section 11 of Chapter 2: tuples
Press the delete key in the gridcontrol of devaxpress to delete the selected line item
(2022 version) zero foundation entry network security /web security, collecting this article is enough
offer - 52. 两个链表的第一个公共节点
C语言三大结构
第二章第三节:字符串常规操作
Section 4 of Chapter 2: replacement and cutting
Classic competition questions web penetration test record
第二章第十一节:元组
架构实战营模块 7 作业
Section 14 of Chapter 2: the concept of dictionary
Networkx visualization graph how to get a graph based on time series
Opportunities and challenges coexist for financial enterprises to go to sea in emerging markets, advance AI ensures its safety and compliance development
Math.random()的用法
PHP人才招聘網站源碼
第二章第十节:列表的补充知识点
Web3 Traffic Aggregation Platform Starfish os, Explaining Real Business' p2e 'Ecology
asp. Net - edit hyperlink event
Section 8 of Chapter II: addition, deletion, modification and query of the list