Adafruit_SSD1306库学习
文章目录
- 1.前言
- 2.SSD1306显示器介绍
- 3.库方法介绍
- 3.1.初始化构造器 *(声明OLED显示器)*
- 3.2 OLED初始化方法
- 3.2.1 begin方法
- 3.2.2 clearDisplay ------清屏
- 3.2.3 display ------ 显示内容
- 3.3绘制类方法
- 3.3.1 drawPixel——绘制像素点
- 3.3.2 drawFastHLine——绘制水平线
- 3.3.3 drawFastVLine——绘制竖直线
- 3.3.4 drawLine——绘制线
- 3.3.5 drawRect——绘制空心矩形
- 3.3.6 fillRect——绘制实心矩形
- 3.3.7 fillScreen —— 点亮全屏
- 3.3.8 drawCircle —— 绘制空心圆
- 3.3.9 fillCircle —— 绘制实心圆
- 3.3.10 drawTriangle —— 绘制空心三角形
- 3.3.11 fillTriangle —— 绘制实心三角形
- 3.3.12 drawRoundRect —— 绘制空心圆角矩形
- 3.3.13 fillRoundRect —— 绘制实心圆角
- 3.3.14 drawBitmap —— 绘制Bitmap图像
- 3.3.15 setTextSize —— 设置字体大小
- 3.3.16 setFont —— 设置字体
- 3.3.17 setCursor —— 设置光标位置
- 3.3.18 setTextWrap —— 设置是否自动换行
- 3.4 获取屏幕参数
- 3.5 屏幕滚动
- 3.5.1 startscrollright —— 向右滚动
- 3.5.2 startscrollleft —— 向左滚动
- 3.5.3 stopscroll —— 停止滚动
- 4.参考资料及博客
1.前言
在这里了解一下Adafruit_SSD1306和Adafruit_GFX这两个库
Adafruti_SSD1306是SSD1306 OLED屏幕的专用显示库
Adafruit_GFX库是LCD和OLED屏幕的通用父类,这是一个父类的图形库
Adafruit_GFX要与屏幕的专用显示库一同使用,子类库依赖父类库
例如:
- SSD1306 OLED显示器:Adafruit_GFX和Adafruit_SSD1306
- ST7735 1.8英寸彩色LCD显示器:Adafruit_GFX,Adafruit_ZeroDMA 和 Adafruit_ST7735
2.SSD1306显示器介绍
OLED显示器可以抽象为像素点,SSD1306显示器就是128x64像素点阵。
OLED显示屏有四个引脚:
SDA:数据线
SCK:时钟线
VDD:电源线(3.3V)
GND:地线
SSD1306驱动的IIC接口的显示屏的默认通信地址为0x3c/0x3d,具体的可通过如下程序查询:
#include <Wire.h> void setup(){ Wire.begin(); Serial.begin(9600); Serial.println("\nI2C Scanner");
}
void loop(){ byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for (address = 1; address < 127; address++ ){ // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0){ Serial.print("I2C device found at address 0x"); if (address < 16) Serial.print("0"); Serial.print(address, HEX); Serial.println(" !"); nDevices++; }else if (error == 4){ Serial.print("Unknow error at address 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan
}
打开串口监视器可查看通信地址
3.库方法介绍
3.1.初始化构造器 (声明OLED显示器)
Adafruit_ssd1306初始化构造器
SSD1306包括IIC和SPI两个版本,本篇现只介绍IIC版本,后续会更新SPI版本
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi=&Wire, int8_t rst_pin=-1,uint32_t clkDuring=400000UL, uint32_t clkAfter=100000UL);
参数介绍:
w:屏幕宽度像素
h:屏幕高度像素
twi:IIC总线实例,默认为&wrie
rst_pin:复位引脚,没有则填-1
clkDuring:SSD1306库调用期间的传输速率,默认为400000(400KHz)
clkAfter:SSD1306库非调用期间的传输速率,为了兼容IIC总线上其它设备,默认为100000(100KHz)
使用代码实例
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//屏幕分辨率
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
3.2 OLED初始化方法
3.2.1 begin方法
boolean Adafruit_SSD1306::begin(uint8_t switchvcc=SSD1306_SWITCHCAPVCC, uint8_t i2caddr=0, boolean reset=true,boolean periphBegin=true)
参数介绍:
switchvcc: OLED的电压
i2caddr: OLED的通信地址
使用代码实例:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
3.2.2 clearDisplay ------清屏
- 此方法只清楚单片机缓存,不会显示在屏幕上,需配合display清屏
void Adafruit_SSD1306::clearDisplay(void)
使用代码实例
display.clearDisplay(); // clears the screen and buffer
3.2.3 display ------ 显示内容
- display方法才会把内容推到显示屏上
使用代码实例
display.diaplay();
3.3绘制类方法
因为Adafruit_SSD1306是继承的Adafruit_GFX,所以绘制类方法分为Adafruit_GFX的父类方法和Adafruit_SSD1306的子类方法:
Adafruit_GFX的父类方法:
drawCircle——绘制空心圆
fillCircle——绘制实心圆
drawTriangle——绘制空心三角形
fillTriangle——绘制实心三角形
drawRoundRect——绘制空心圆角方形
fillRoundRect——绘制实心圆角方形
drawBitmap——绘制Bitmap图像
drawXBitmap——绘制XBitmap图像
drawGrayscaleBitmap
drawRGBBitmap
drawChar——绘制字符
getTextBounds——绘制单个字母
setTextSize——设置字号
setFont——设置字体
setCursor——设置光标起始坐标
setTextColor——设置字体颜色
setTextWrap
Adafruit_SSD1306子类方法:
- drawPixel——绘制像素点
- drawFastHLine——绘制水平线
- drawFastVLine——绘制垂直线
- startscrollright——滚动到右边
- startscrollleft——滚动到左边
- startscrolldiagright——沿对角线右滚动
- startscrolldiagleft——沿对角线左滚动
- stopscroll——停止滚动
3.3.1 drawPixel——绘制像素点
void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color)
参数介绍:
x:x坐标,横坐标
y:y坐标,纵坐标
color:绘制颜色,SSD1306_BLACK , SSD1306_WHITE , SSD1306_INVERT
使用代码实例
display.clearDisplay(); // clears the screen and bufferdisplay.drawPixel(64, 32, WHITE);display.display();delay(2000);
3.3.2 drawFastHLine——绘制水平线
void Adafruit_SSD1306::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
参数介绍:
x:起始坐标x,取值范围:0 ~ width-1
y:起始坐标y,取值范围:0 ~ height-1
w:水平线长度,单位:像素
color:水平线颜色:SSD1306_BLACK , SSD1306_WHITE , SSD1306_INVERT
display.clearDisplay();display.drawFastHLine(0,10,50,SSD1306_WHITE);display.display();delay(2000);
3.3.3 drawFastVLine——绘制竖直线
void Adafruit_SSD1306::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
参数介绍:
x:起始坐标x,取值范围:0 ~ width-1
y:起始坐标y,取值范围:0 ~ height-1
h:竖直线长度
color:竖直线颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
使用代码示例:
display.clearDisplay();display.drawFastVLine(0,10,50,SSD1306_WHITE);display.display();delay(2000);
3.3.4 drawLine——绘制线
void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,uint16_t color)
参数介绍:
x0:起始坐标x
y0:起始坐标y
x1:终点坐标x
y1:终点坐标y
color:线颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.drawLine(10,10,100,60,SSD1306_WHITE);display.display();delay(2000);
3.3.5 drawRect——绘制空心矩形
void Adafruit_GFX::drawRect(int16_t x, int16_t y, int16_t w, int16_t h,uint16_t color)
参数介绍:
x:左上角x坐标
y:左上角y坐标
w:矩形宽
h:矩形高
color:矩形颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.drawRect(0,0,128,64,SSD1306_WHITE);display.display();delay(20);
3.3.6 fillRect——绘制实心矩形
void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,uint16_t color)
参数介绍:
x:左上角x坐标
y:左上角y坐标
w:矩形宽
h:矩形高
color:矩形颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.fillRect(20,10,88,44,SSD1306_WHITE);display.display();delay(2000);
3.3.7 fillScreen —— 点亮全屏
void Adafruit_GFX::fillScreen(uint16_t color)
参数介绍:
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.fillScreen(SSD1306_WHITE);display.display();delay(2000);
3.3.8 drawCircle —— 绘制空心圆
void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,uint16_t color)
参数介绍:
x0:圆心x坐标
y0:圆心y坐标
r:半径
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.drawCircle(64,32,32,SSD1306_WHITE);display.display();delay(2000);
3.3.9 fillCircle —— 绘制实心圆
void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,uint16_t color)
参数介绍:
x0:圆心x坐标
y0:圆心y坐标
r:半径
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.fillCircle(64,32,31,SSD1306_WHITE);display.display();delay(2000);
3.3.10 drawTriangle —— 绘制空心三角形
void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0,int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
参数介绍:
x0:第一个顶点x坐标
y0:第一个顶点y坐标
x1:第二个顶点x坐标
y1:第二个顶点y坐标
x2:第三个顶点x坐标
y2:第三个顶点y坐标
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.drawTriangle(63,0, 0,63, 127,63, SSD1306_WHITE);display.display();delay(2000);
3.3.11 fillTriangle —— 绘制实心三角形
void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0,int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
参数介绍:
x0:第一个顶点x坐标
y0:第一个顶点y坐标
x1:第二个顶点x坐标
y1:第二个顶点y坐标
x2:第三个顶点x坐标
y2:第三个顶点y坐标
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.fillTriangle(63,0, 0,63, 127,63, SSD1306_WHITE);display.display();delay(2000);
3.3.12 drawRoundRect —— 绘制空心圆角矩形
void Adafruit_GFX::drawRoundRect(int16_t x, int16_t y, int16_t w,int16_t h, int16_t r, uint16_t color)
参数介绍:
x:左上角x坐标
y:左上角y坐标
w:矩形宽
h:矩形高
r:矩形圆角半径
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
display.clearDisplay();display.drawRoundRect(10,5,107, 43,3, SSD1306_WHITE);display.display();delay(2000);
3.3.13 fillRoundRect —— 绘制实心圆角
void Adafruit_GFX::fillRoundRect(int16_t x, int16_t y, int16_t w,int16_t h, int16_t r, uint16_t color)
参数介绍:
x:左上角x坐标
y:左上角y坐标
w:矩形宽
h:矩形高
r:矩形圆角半径
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
代码示例:
//绘制实心圆角矩形display.clearDisplay();display.fillRoundRect(10,5,107,53,3, SSD1306_WHITE);display.display();delay(2000);
3.3.14 drawBitmap —— 绘制Bitmap图像
使用PROGMEM的图形
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],int16_t w, int16_t h, uint16_t color)
参数介绍:
x:左上角x坐标
y:左上角y坐标
bitmap[]:图形数据
w:图形宽
h:图形高
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],int16_t w, int16_t h, uint16_t color, uint16_t bg)
参数介绍:
bg:背景颜色(部分显示器支持)
使用ram的图形
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,int16_t w, int16_t h, uint16_t color)
参数介绍:
x:左上角x坐标
y:左上角y坐标
bitmap:图形数据
w:图形宽
h:图形高
color:颜色:SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERT
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,int16_t w, int16_t h, uint16_t color, uint16_t bg)
bg:背景颜色(部分显示器支持)
代码示例:
//Bimap图像数据
static const unsigned char PROGMEM BimptPhoto_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,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,0x03,0xF0,0x01,0xF0,0x03,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x1E,0x3F,0x1C,0x1E,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xE0,0x07,0xF0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0F,0xFE,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x70,0x03,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x07,0xFE,0x00,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x7F,0xD0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x3F,0xC0,0x3E,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xE0,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//显示Bimap图像display.clearDisplay();display.drawBitmap(0,0,BimptPhoto_128x64,128,64,SSD1306_WHITE);display.display();delay(2000);
3.3.15 setTextSize —— 设置字体大小
- 单参数
void Adafruit_GFX::setTextSize(uint8_t s)
参数介绍:
s:字体大小倍数,s为1时为6x8,s为2时为12x16
代码示例:
display.clearDisplay();display.setTextSize(1); //选择字号display.setTextColor(WHITE); //字体颜色display.setCursor(0,8);display.print("setTextSize: 1");display.display();delay(2000);
- 双参数
void Adafruit_GFX::setTextSize(uint8_t s_x, uint8_t s_y)
参数介绍:
s_x:字体横向倍数大小
s_y:字体纵向倍数大小
代码示例:
display.clearDisplay();display.setTextSize(1); //选择字号display.setTextColor(WHITE); //字体颜色display.setTextSize(1,2);display.setCursor(0,20);display.print("setTextSize: 6x16");delay(2000);
3.3.16 setFont —— 设置字体
void Adafruit_GFX::setFont(const GFXfont *f)
参数设置:
f:使用display.print()时的字体,不使用此函数系统默认为6x8
暂时没整明白怎么使用
3.3.17 setCursor —— 设置光标位置
void setCursor(int16_t x, int16_t y)
参数介绍:
x:光标顶点x坐标
y:光标顶点y坐标
代码示例:
display.clearDisplay();display.setTextSize(1); //选择字号display.setTextColor(WHITE); //字体颜色display.setCursor(0,0);display.print("setCursor(0,0)");display.setCursor(0,8);display.print("setCursor(0,8)");display.display();delay(2000);
3.3.18 setTextWrap —— 设置是否自动换行
void setTextWrap(boolean w) { wrap = w; }
参数介绍:
w:true or false
3.4 获取屏幕参数
获取屏幕高度
int16_t width(void)
获取屏幕宽度
int16_t height(void)
获取屏幕旋转角度
uint8_t getRotation(void)
获取光标x坐标
int16_t getCursorX(void)
获取光标y坐标
int16_t getCursorY(void)
3.5 屏幕滚动
3.5.1 startscrollright —— 向右滚动
void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop)
代码示例:
display.clearDisplay();display.setTextSize(1); //选择字号display.setTextColor(WHITE); //字体颜色display.setCursor(8,32);display.setTextWrap(false);display.print("ABC");display.startscrollright(31,40);display.display();delay(5000);
3.5.2 startscrollleft —— 向左滚动
void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop)
代码示例:
display.clearDisplay();display.setTextSize(1); //选择字号display.setTextColor(WHITE); //字体颜色display.setCursor(110,32);display.setTextWrap(false);display.print("abcdefghiJKLMNOPQRSTUVWXYZ");display.startscrollleft(31,40);display.display();delay(5000);
3.5.3 stopscroll —— 停止滚动
void Adafruit_SSD1306::stopscroll(void)
4.参考资料及博客
深入学习 OLED Adafruit_SSD1306库(8266+arduino)
关于Arduino&SSD1306OLED(IIC)显示的学习
Adafruit_SSD1306库学习相关推荐
- 【libevent】libevent库学习总结(一)——基础
libevent库学习总结(一)--基础 一.基础 1.1. 介绍 Libevent是一个用于开发可伸缩网络服务器的事件通知库.Libevent API提供了一种机制来执行回调函数,当某个特定事件发生 ...
- Guava库学习:学习Guava EventBus(二)EventBus 事件订阅示例
2019独角兽企业重金招聘Python工程师标准>>> 原文地址:Guava库学习:学习Guava EventBus(二)EventBus 事件订阅示例 上一篇Guava库学习:学习 ...
- POCO C++库学习和分析
POCO C++库学习和分析 -- 序 1. POCO库概述: POCO是一个C++的开源库集.同一般的C++库相比,POCO的特点是提供了整一个应用框架.如果要做C++程序应用框架的快速开发,我觉得 ...
- muduo网络库学习(八)事件驱动循环线程池EventLoopThreadPool
muduo是支持多线程的网络库,在muduo网络库学习(七)用于创建服务器的类TcpServer中也提及了TcpServer中有一个事件驱动循环线程池,线程池中存在大量线程,每个线程运行一个Event ...
- muduo网络库学习(七)用于创建服务器的类TcpServer
目前为止,涉及到的绝大多数操作都没有提及线程,EventLoop,Poller,Channel,Acceptor,TcpConnection,这些对象的执行都是在单独线程完成,并没有设计多线程的创建销 ...
- muduo网络库学习(四)事件驱动循环EventLoop
muduo的设计采用高并发服务器框架中的one loop per thread模式,即一个线程一个事件循环. 这里的loop,其实就是muduo中的EventLoop,所以到目前为止,不管是Polle ...
- python xlwings 切片_Python xlwings库学习笔记(1)
Python xlwings库学习笔记(1) Python是最近几年很火的编程语言,被办公自动化的宣传吸引入坑,办公自动化必然绕不开Excel的操作,能操作Excel的库有很多,例如: xlrd xl ...
- python标准库学习笔记
原创:python标准库学习笔记 数据结构 bisect 模块里实现了一个向列表插入元素时也会顺便排序的算法. struct - 二进制数据结构:用途:在 Python 基本数据类型和二进制数据之间进 ...
- requests库学习
requests库学习 requests快速上手 http://2.python-requests.org/zh_CN/latest/user/quickstart.html Requests库是用来 ...
- Guava库学习:学习Concurrency(九)RateLimiter
2019独角兽企业重金招聘Python工程师标准>>> 链接地址:http://www.xx566.com/detail/164.html 上一篇,Guava库学习:学习Concur ...
最新文章
- 把eclipse从英文调整为中文
- Centos6.5 rpm方式指定目录安装JDK
- SQL Server 2008 缩小数据库日志
- MMCME2_ADV介绍 高级混合模式时钟管理器(7 Series FPGA)
- Linux 信号signal处理函数
- java hql 查询所有内容,HQL查询语言转载
- 我的考研~~~3-4月份总结
- SequoiaDB版本升级及导入导出工具说明
- 项目搭建 windows_08. SpringCloud实战项目-配置Git
- 如何在csdn网站搜索自己写的博客文章
- 超人视觉助我成功转型机器视觉行业
- 电子或计算机机类学校,热门理工科工程专业当然属于计算机、电子信息和机械...
- 非线性微分方程线性化
- Ubuntu16.04关机后自动重启解决方案
- 代码走查工具篇FxCop的规则总结与翻译_Part2
- oracle 取月份的第一天
- navicat cannot create file 文件名、目录名或卷标语法不正确 解决方法
- react手机号码344格式分割
- 车用永磁电机的各种弱磁策略
- 青岛企业掘金大数据时代 大数据时代已经来临