SSD 1306显示屏 adafruit SSD 1306
创始人
2024-02-06 07:14:30
0

文章目录

    • 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 
#include 
#include 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  3oled.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 
#include 
#include 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 );//coloroled.display();  delay(5000);    oled.clearDisplay();//清屏//填充矩形oled.fillRect(10, 10, 20, 20, WHITE );//x y x1 y1 coloroled.display();  delay(5000);    oled.clearDisplay();//清屏//边框矩形oled.drawRect(10, 10, 40,40, WHITE );//x y x1 y1 coloroled.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   coloroled.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 
#include 
#include 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   coloroled.display();  delay(5000);    oled.clearDisplay();//清屏oled.drawLine(10,10,50,60,WHITE);//x1 y1 x2 y2   coloroled.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 
#include 
#include 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,coloroled.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 
#include 
#include 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 
#include 
#include 
/*--  调入了一幅图像: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();//清屏}

相关内容

热门资讯

人文天津 和合共生——从河海文...   西青区杨柳青古镇。 记者 潘立峰 摄  古文化街宫前广场民俗花会表演。  记者 胡凌云 摄  滨...
“水上奇兵”雁翎队(文化中国行...   图①:雁翎队使用过的提灯和用具。  图②:“大抬杆”信口点火处使用的雁翎。  图③:白洋淀航拍。...
韩媒:韩日首脑会谈讨论对美谈判...   【环球网报道】据韩国《中央日报》报道,韩国国家安保室长魏圣洛24日表示,韩国总统李在明与日本首相...
基孔肯雅热或人传人?咖啡灌肠能...   AI已经足够聪明,可以当心理咨询师?  流言:AI现在已经非常厉害,情商很高,能够洞察人们的心理...
山海之城展新姿 传递蔚蓝“和合...   山海相拥,共赴蔚蓝。在上合峰会即将召开之际,8月21日至8月23日,中央广播电视总台CGTN“一...
深化科技创新引领新质生产力发展   近期召开的中央政治局会议强调,要坚持以科技创新引领新质生产力发展,加快培育具有国际竞争力的新兴支...
第二十届中国长春电影节开幕   8月23日晚,伴随着新中国第一支国家级电影交响乐团长影乐团奏响昂扬乐章,第二十届中国长春电影节开...
校企协作实现我国柔性钙钛矿光伏...   记者从南京大学获悉,该校谭海仁教授牵头的研究团队在柔性钙钛矿叠层光伏电池领域取得新突破。团队开发...
【活力中国调研行】敕勒川生态草...   在内蒙古自治区呼和浩特市的敕勒川生态草原,蓝天白云下,牧人赶着牛群与远处的蒙古包相映成趣。风过时...
决胜“十四五” 打好收官战|孩...   托育服务,关系千家万户,是缓解家庭育儿压力、促进人口长期均衡发展的重要民生工程。  扩大普惠性托...