|
|
引述:
制作完世界時(shí)鐘之后,最終還是要回歸本心。我們發(fā)現(xiàn),和之前的電子作品一樣,OLED模塊的拓展使用會(huì)用到不同相關(guān)的軟件庫(kù),這些軟件庫(kù)的使用是豐富了OLED的實(shí)用范圍,使得我們制作的電子產(chǎn)品也更加的多樣化,在生活中的使用范圍也更加廣泛。這同時(shí)也推動(dòng)了我們了解電子世界的進(jìn)程,現(xiàn)在的你,應(yīng)該對(duì)電子世界有一個(gè)大概的輪廓了吧。
同理,其他模塊的使用也和本次分享的引述一樣,擁有更大的發(fā)展?jié)摿Γ@就取決于我們作為開(kāi)發(fā)者的想象力了。
接下來(lái),我們繼續(xù)分享學(xué)習(xí)。
本次分享則繼續(xù)在零知ESP8266上使用OLED,加深我們對(duì)OLED模塊的認(rèn)識(shí)。
一、硬件
電腦,windows系統(tǒng)
零知ESP8266開(kāi)發(fā)板
OLED SSD1306模塊
micro-usb線
二、連線
三、軟件庫(kù)
(1)本次使用了OLED相關(guān)的軟件庫(kù),因此需要安裝如下兩個(gè)庫(kù):
Tip:如果你的電腦已在零知實(shí)驗(yàn)室“軟件下載”處安裝了最新的零知開(kāi)發(fā)工具(如下圖),即可跳過(guò)此步驟。
1. Adafruit_SSD1306
2. Adafruit-GFX
(2)安裝
在零知實(shí)驗(yàn)室官網(wǎng)搜索:本地庫(kù),即可安裝。
同時(shí)也可以給我留言,我們一起交流學(xué)習(xí)。
(3)燒錄程序
在這里我們選中SSD1306的示例即可。
其完整代碼如下:
- <font size="3">#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 -1 // Reset pin # (or -1 if sharing Arduino reset pin)
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
-
- #define NUMFLAKES 10 // Number of snowflakes in the animation example
-
- #define LOGO_HEIGHT 16
- #define LOGO_WIDTH 16
- static const unsigned char PROGMEM logo_bmp[] =
- { B00000000, B11000000,
- B00000001, B11000000,
- B00000001, B11000000,
- B00000011, B11100000,
- B11110011, B11100000,
- B11111110, B11111000,
- B01111110, B11111111,
- B00110011, B10011111,
- B00011111, B11111100,
- B00001101, B01110000,
- B00011011, B10100000,
- B00111111, B11100000,
- B00111111, B11110000,
- B01111100, B11110000,
- B01110000, B01110000,
- B00000000, B00110000 };
-
- void setup() {
- Serial.begin(9600);//設(shè)置打印波特率
-
- Serial.println("SSD1306 i2c example");
-
- // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
- if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
- Serial.println(F("SSD1306 allocation failed"));
- for(;;); // Don't proceed, loop forever
- }
-
- // Show initial display buffer contents on the screen --
- // the library initializes this with an Adafruit splash screen.
- display.display();
- delay(2000); // Pause for 2 seconds
-
- // Clear the buffer
- display.clearDisplay();
-
- // Draw a single pixel in white
- display.drawPixel(10, 10, WHITE);
-
- // Show the display buffer on the screen. You MUST call display() after
- // drawing commands to make them visible on screen!
- display.display();
- delay(2000);
- // display.display() is NOT necessary after every single drawing command,
- // unless that's what you want...rather, you can batch up a bunch of
- // drawing operations and then update the screen all at once by calling
- // display.display(). These examples demonstrate both approaches...
-
- testdrawline(); // Draw many lines
-
- testdrawrect(); // Draw rectangles (outlines)
-
- testfillrect(); // Draw rectangles (filled)
-
- testdrawcircle(); // Draw circles (outlines)
-
- testfillcircle(); // Draw circles (filled)
-
- testdrawroundrect(); // Draw rounded rectangles (outlines)
-
- testfillroundrect(); // Draw rounded rectangles (filled)
-
- testdrawtriangle(); // Draw triangles (outlines)
-
- testfilltriangle(); // Draw triangles (filled)
-
- testdrawchar(); // Draw characters of the default font
-
- testdrawstyles(); // Draw 'stylized' characters
-
- testscrolltext(); // Draw scrolling text
-
- testdrawbitmap(); // Draw a small bitmap image
-
- // Invert and restore display, pausing in-between
- display.invertDisplay(true);
- delay(1000);
- display.invertDisplay(false);
- delay(1000);
-
- testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
- }
-
- void loop() {
- }
- </font>
復(fù)制代碼
(4)驗(yàn)證代碼,并且上傳
四、結(jié)果
效果視頻:親自實(shí)現(xiàn)是極好的,小主
演示效果極佳,快來(lái)動(dòng)手試試吧! |
|