#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#define SCREEN_WIDTH 128 // OLED 寬度像素
#define SCREEN_HEIGHT 64 // OLED 高度像素
// 設定OLED
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SH1106G display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void testdrawstyles(void) {
display.clearDisplay();
display.setTextSize(2); // 設定文字大小
display.setTextColor(1); // 1:OLED預設的顏色(這個會依該OLED的顏色來決定)
display.setCursor(5,0); // 設定起始座標
display.print("Hello!!!!"); // 要顯示的字串
display.setCursor(20,40); // 設定起始座標
display.print("OLED test"); // 要顯示的字串
display.display(); // 要有這行才會把文字顯示出來
delay(1000);
}
void setup() {
Serial.begin(115200);
// 偵測是否安裝好OLED了
if(!display.begin(0x3C, true)) { // 一般1306 OLED的位址都是0x3C
Serial.println(F("SH110X allocation failed"));
for(;;); // Don't proceed, loop forever
}
Serial.println(F("OK"));
display.clearDisplay(); // 清除畫面
testdrawstyles(); // 測試文字
delay(1000);
}
void loop() {
}