#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.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_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void testdrawstyles(void) {
display.clearDisplay();
display.setTextSize(2); // 設定文字大小
display.setTextColor(2); // 1:OLED預設的顏色(這個會依該OLED的顏色來決定)
display.setCursor(5, 0); // 設定起始座標
display.print("Hello OLED"); // 要顯示的字串
display.setCursor(26, 40); // 設定起始座標
display.print("Arduino"); // 要顯示的字串
display.display(); // 要有這行才會把文字顯示出來
delay(500);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// 偵測是否安裝好OLED了
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // 一般1306 OLED的位址都是0x3C
Serial.println(F("SSD1306 allocation failed"));
//for (;;); // Don't proceed, loop forever
}
display.clearDisplay(); // 清除畫面
delay(1000);
testdrawstyles(); // 測試文字
delay(500);
}
void loop() {
// put your main code here, to run repeatedly:
display.clearDisplay(); // 清除畫面
delay(1000);
testdrawstyles(); // 測試文字
delay(1000);
}