//相關函式
#include <Wire.h> //For I2C
#include <Adafruit_GFX.h> //For文字圖形顯示
#include <Adafruit_SSD1306.h> //驅動
// 設定OLED SSD1306
#define SCREEN_WIDTH 128 // OLED 寬度像素
#define SCREEN_HEIGHT 64 // OLED 高度像素
#define OLED_RESET -1 //可與晶片共用重置腳,無需reset腳,設為-1
Adafruit_SSD1306 ssd(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//顯示文字的副程式
void ShowText(void) {
ssd.clearDisplay();
ssd.setTextColor(1); // 由產品決定,通常為白色
ssd.setTextSize(1); // 設定字體大小1
ssd.setCursor(0,0); // 設定起始座標
ssd.print("012345678901234567890"); // 要顯示的字串
ssd.print("123456789012345678901"); // 要顯示的字串
ssd.print("234567890123456789012"); // 要顯示的字串
ssd.print("345678901234567890123"); // 要顯示的字串
ssd.print("456789012345678901234"); // 要顯示的字串
ssd.print("567890123456789012345"); // 要顯示的字串
ssd.print("678901234567890123456"); // 要顯示的字串
ssd.print("789012345678901234567"); // 要顯示的字串
ssd.display(); // 把文字顯示出來
}
void setup() {
Serial.begin(115200);
//偵測OLED是否正常,一般的位址都是0x3C
if(!ssd.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); //不讓執行下去
}
ShowText(); //測試顯示文字大小顏色
}
void loop() { }