SSD1306 128x64 OLED 【四】Adafruit / GFX Library


Adafruit Library使用時的基本概念

Library支援畫 點drawPixel()/ 線drawLine()/ 圓drawCircle()/ 直角drawRect

但這些函式所修改的是Library另外宣告的buffer[];所以修改不會立刻顯示在OLED上

執行display()才會顯示 (預設載入Adafruit logo)



display()

將buffer[]的圖形輸出顯示

預設載入Adafruit的logo,logo的圖檔儲放在

C:\Users\"pc_name"\Documents\Arduino\libraries\Adafruit_SSD1306\splash.h 的splash1_data[]

#include <SPI.h>
#include <Wire.h.h>
#include <Adafruit_GFX.h.h>
#include <Adafruit_SSD1306.h.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)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c //See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  } 

  display.display();
}

void loop() {
  // put your main code here, to run repeatedly:
}


drawLine()

Adafruit_GFX.h

virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);



留言