找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1329|回复: 0
收起左侧

【零知ESP8266教程】快速入门22 OLED模块的再探索

[复制链接]
ID:349555 发表于 2019-11-6 16:23 | 显示全部楼层 |阅读模式
引述:
制作完世界时钟之后,最终还是要回归本心。我们发现,和之前的电子作品一样,OLED模块的拓展使用会用到不同相关的软件库,这些软件库的使用是丰富了OLED的实用范围,使得我们制作的电子产品也更加的多样化,在生活中的使用范围也更加广泛。这同时也推动了我们了解电子世界的进程,现在的你,应该对电子世界有一个大概的轮廓了吧。

同理,其他模块的使用也和本次分享的引述一样,拥有更大的发展潜力,这就取决于我们作为开发者的想象力了。

接下来,我们继续分享学习。
本次分享则继续在零知ESP8266上使用OLED,加深我们对OLED模块的认识。
一、硬件
电脑,windows系统
零知ESP8266开发板
OLED SSD1306模块
micro-usb线

二、连线
1.jpg

2.jpg

三、软件库
(1)本次使用了OLED相关的软件库,因此需要安装如下两个库:
Tip:如果你的电脑已在零知实验室“软件下载”处安装了最新的零知开发工具(如下图),即可跳过此步骤。
3.jpg
1. Adafruit_SSD1306
2. Adafruit-GFX

(2)安装
在零知实验室官网搜索:本地库,即可安装。

同时也可以给我留言,我们一起交流学习。

(3)烧录程序
在这里我们选中SSD1306的示例即可。
code.png

其完整代码如下:
  1. <font size="3">#include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5.   
  6. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  7. #define SCREEN_HEIGHT 64 // OLED display height, in pixels
  8.   
  9. // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
  10. #define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
  11. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  12.   
  13. #define NUMFLAKES     10 // Number of snowflakes in the animation example
  14.   
  15. #define LOGO_HEIGHT   16
  16. #define LOGO_WIDTH    16
  17. static const unsigned char PROGMEM logo_bmp[] =
  18. { B00000000, B11000000,
  19.   B00000001, B11000000,
  20.   B00000001, B11000000,
  21.   B00000011, B11100000,
  22.   B11110011, B11100000,
  23.   B11111110, B11111000,
  24.   B01111110, B11111111,
  25.   B00110011, B10011111,
  26.   B00011111, B11111100,
  27.   B00001101, B01110000,
  28.   B00011011, B10100000,
  29.   B00111111, B11100000,
  30.   B00111111, B11110000,
  31.   B01111100, B11110000,
  32.   B01110000, B01110000,
  33.   B00000000, B00110000 };
  34.   
  35. void setup() {
  36.   Serial.begin(9600);//设置打印波特率
  37.    
  38.   Serial.println("SSD1306 i2c example");
  39.   
  40.   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  41.   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
  42.     Serial.println(F("SSD1306 allocation failed"));
  43.     for(;;); // Don't proceed, loop forever
  44.   }
  45.   
  46.   // Show initial display buffer contents on the screen --
  47.   // the library initializes this with an Adafruit splash screen.
  48.   display.display();
  49.   delay(2000); // Pause for 2 seconds
  50.   
  51.   // Clear the buffer
  52.   display.clearDisplay();
  53.   
  54.   // Draw a single pixel in white
  55.   display.drawPixel(10, 10, WHITE);
  56.   
  57.   // Show the display buffer on the screen. You MUST call display() after
  58.   // drawing commands to make them visible on screen!
  59.   display.display();
  60.   delay(2000);
  61.   // display.display() is NOT necessary after every single drawing command,
  62.   // unless that's what you want...rather, you can batch up a bunch of
  63.   // drawing operations and then update the screen all at once by calling
  64.   // display.display(). These examples demonstrate both approaches...
  65.   
  66.   testdrawline();      // Draw many lines
  67.   
  68.   testdrawrect();      // Draw rectangles (outlines)
  69.   
  70.   testfillrect();      // Draw rectangles (filled)
  71.   
  72.   testdrawcircle();    // Draw circles (outlines)
  73.   
  74.   testfillcircle();    // Draw circles (filled)
  75.   
  76.   testdrawroundrect(); // Draw rounded rectangles (outlines)
  77.   
  78.   testfillroundrect(); // Draw rounded rectangles (filled)
  79.   
  80.   testdrawtriangle();  // Draw triangles (outlines)
  81.   
  82.   testfilltriangle();  // Draw triangles (filled)
  83.   
  84.   testdrawchar();      // Draw characters of the default font
  85.   
  86.   testdrawstyles();    // Draw 'stylized' characters
  87.   
  88.   testscrolltext();    // Draw scrolling text
  89.   
  90.   testdrawbitmap();    // Draw a small bitmap image
  91.   
  92.   // Invert and restore display, pausing in-between
  93.   display.invertDisplay(true);
  94.   delay(1000);
  95.   display.invertDisplay(false);
  96.   delay(1000);
  97.   
  98.   testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
  99. }
  100.   
  101. void loop() {
  102. }
  103. </font>
复制代码


(4)验证代码,并且上传

四、结果
效果视频:亲自实现是极好的,小主


演示效果极佳,快来动手试试吧!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表