文章目录
- 1.常用函数
- 1.字体
- oled.print
- oled.setRotation(1);
- oled.setTextSize(1);
- oled.setCursor(35, 5);
- 2.图形类
- oled.fillScreen(WHITE );//color
- oled.fillRect(10, 10, 20, 20, WHITE );//x y x1 y1 color
- oled.drawRect(10, 10, 40,40, WHITE );//x y x1 y1 color
- oled.drawCircle(20, 200, 20, WHITE );
- oled.fillCircle(20, 20, 30, WHITE );//x y r color
- --------------------------------------------------------------------------------------------
- oled.drawFastHLine(10,10,50,WHITE);//x y :坐标、 w:长度 、 color、
- oled.drawFastVLine(10,10,50,WHITE);//x y :坐标、 w:长度 、 color
- oled.drawLine(10,10,50,60,WHITE);//x1 y1 x2 y2 color
- --------------------------------------------------------------------------------------------
- oled.drawTriangle(10,10,20,10,15,40,WHITE); //边框三角形
- oled.fillTriangle(10,10,20,10,15,40,WHITE);//x1 y1 ,x2 y2,x3 y3,color //填充三角形
- oled.drawRoundRect(10,10,30,40,5,WHITE);//x, y , w, h ,r, color, //边框椭圆矩形
- oled.fillRoundRect(10,10,30,40,5,WHITE);//x, y , w, h ,r, color,//填充椭圆矩形
- 3.显示汉字
- 3-1:常见问题可以跳转这个链接
- 4.显示图片bmp
为什么OLED能用Print函数:
继承了print
1.常用函数
这几个函数都在GFX库中
1.字体
oled.print
oled.setRotation(1);
oled.setTextSize(1);
oled.setCursor(35, 5);
/*
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire,-1);
void setup()
{
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
}
void loop() {
oled.setRotation(1);
oled.setTextColor(WHITE);//开像素点发光
oled.clearDisplay();//清屏
//设置字体大小
oled.setTextSize(1); //设置字体大小
//设置显示位置
oled.setCursor(35, 5);//设置显示位置
oled.println("-TonyCode-");
oled.display(); delay(5000);oled.clearDisplay();//开启显示----5秒----关闭显示
oled.setRotation(2);
oled.setTextSize(2);//设置字体大小
oled.setCursor(15, 30);//设置显示位置
oled.println("OLED TEST");
oled.display(); delay(5000); oled.clearDisplay();//清屏
}
oled.setRotation(2);//可以选择0 1 2 3
oled.setTextSize(2);//设置字体大小
2.图形类
oled.fillScreen(WHITE );//color
oled.fillRect(10, 10, 20, 20, WHITE );//x y x1 y1 color
oled.drawRect(10, 10, 40,40, WHITE );//x y x1 y1 color
oled.drawCircle(20, 200, 20, WHITE );
oled.fillCircle(20, 20, 30, WHITE );//x y r color
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire,-1);
void setup()
{
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
oled.setRotation(2);
}
void loop() {
oled.setTextColor(WHITE);//开像素点发光
oled.clearDisplay();//清屏
//填充整屏
oled.fillScreen(WHITE );//color
oled.display(); delay(5000); oled.clearDisplay();//清屏
//填充矩形
oled.fillRect(10, 10, 20, 20, WHITE );//x y x1 y1 color
oled.display(); delay(5000); oled.clearDisplay();//清屏
//边框矩形
oled.drawRect(10, 10, 40,40, WHITE );//x y x1 y1 color
oled.display(); delay(5000); oled.clearDisplay();//清屏
//边框圆形
oled.drawCircle(20, 200, 20, WHITE );
oled.display(); delay(5000); oled.clearDisplay();//清屏
//填充圆形
oled.fillCircle(20, 20, 30, WHITE );//x y r color
oled.display(); delay(5000); oled.clearDisplay();//清屏
}
--------------------------------------------------------------------------------------------
oled.drawFastHLine(10,10,50,WHITE);//x y :坐标、 w:长度 、 color、
oled.drawFastVLine(10,10,50,WHITE);//x y :坐标、 w:长度 、 color
oled.drawLine(10,10,50,60,WHITE);//x1 y1 x2 y2 color
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire,-1);
void setup()
{
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
oled.setRotation(2);
}
void loop() {
oled.setTextColor(WHITE);//开像素点发光
oled.drawFastHLine(10,10,50,WHITE);//x y :坐标、 w:长度 、 color、
oled.display(); delay(5000); oled.clearDisplay();//清屏
oled.drawFastVLine(10,10,50,WHITE);//y1 y2 w color
oled.display(); delay(5000); oled.clearDisplay();//清屏
oled.drawLine(10,10,50,60,WHITE);//x1 y1 x2 y2 color
oled.display(); delay(5000); oled.clearDisplay();//清屏
}
--------------------------------------------------------------------------------------------
oled.drawTriangle(10,10,20,10,15,40,WHITE); //边框三角形
oled.fillTriangle(10,10,20,10,15,40,WHITE);//x1 y1 ,x2 y2,x3 y3,color //填充三角形
oled.drawRoundRect(10,10,30,40,5,WHITE);//x, y , w, h ,r, color, //边框椭圆矩形
oled.fillRoundRect(10,10,30,40,5,WHITE);//x, y , w, h ,r, color,//填充椭圆矩形
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire,-1);
void setup()
{
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
oled.setRotation(2);
}
void loop() {
oled.setTextColor(WHITE);//开像素点发光
//边框三角形
oled.drawTriangle(10,10,20,10,15,40,WHITE);
oled.display(); delay(5000); oled.clearDisplay();//清屏
//填充三角形
oled.fillTriangle(10,10,20,10,15,40,WHITE);//x1 y1 ,x2 y2,x3 y3,color
oled.display(); delay(5000); oled.clearDisplay();//清屏
//边框椭圆矩形
oled.drawRoundRect(10,10,30,40,5,WHITE);//x, y , w, h ,r, color,
oled.display(); delay(5000); oled.clearDisplay();//清屏
//填充椭圆矩形
oled.fillRoundRect(10,10,30,40,5,WHITE);//x, y , w, h ,r, color,
oled.display(); delay(5000); oled.clearDisplay();//清屏
}
3.显示汉字
3-1:用这个软件取模
https://www.jb51.net/softs/109793.html#downintro2
3-2:在文字输入框输入文字,按着Ctrl+enter 就输入进去了
3-3:在取模方式项选择C51格式生成代码
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
static const uint8_t PROGMEM Strong_16x16[] = {/*-- 文字: 我 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
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,};
static const uint8_t PROGMEM Strong1_16x16[] = {/*-- 文字: 猜 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x20,0x44,0x20,0x2B,0xFE,0x10,0x20,0x29,0xFC,0x48,0x20,0x8B,0xFE,0x08,0x00,
0x19,0xFC,0x29,0x04,0x49,0xFC,0x89,0x04,0x09,0xFC,0x09,0x04,0x51,0x14,0x21,0x08,};
Adafruit_SSD1306 oled(128, 64, &Wire,-1);
void setup()
{
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
}
void loop() {
oled.setRotation(1);
oled.drawBitmap(16,16,Strong_16x16,16,16,WHITE); //(16,16)起点坐标,
oled.drawBitmap(16+16,16,Strong1_16x16,16,16,WHITE); //(16,16)起点坐标,
oled.display(); delay(5000); oled.clearDisplay();//清屏
}
3-1:常见问题可以跳转这个链接
https://blog.csdn.net/qq_42860728/article/details/84310160
4.显示图片bmp
4-1:在网上下载一张图片
4-2:用PS打开
修改长和高(如128X64)
4-3:另存为
4-4:用刚刚用到的汉字取模软件打开
C51 格式,复制粘贴到下面的代码中
4-5:显示成功
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/*-- 调入了一幅图像:C:\Users\lz\Desktop\未标题-3.bmp --*/
/*-- 宽度x高度=128x64 --*/
static const uint8_t PROGMEM photo_128x64[] = {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,
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,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFB,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xF7,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xEE,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x07,0xF3,0xDC,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0x3F,0xFF,0xF8,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xF0,0x7F,0xFF,0x60,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFD,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x19,0xEF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1B,0xC7,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x83,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3F,0x80,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,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,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,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,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,};
Adafruit_SSD1306 oled(128, 64, &Wire,-1);
void setup()
{
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
}
void loop() {
oled.setRotation(2);
oled.drawBitmap(0,0,photo_128x64,128,64,WHITE); //(16,16)起点坐标,
oled.display(); delay(5000); oled.clearDisplay();//清屏
}