0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Adafruit_SSD1306を解析して遊ぶ

Last updated at Posted at 2023-06-13

目的
俺の考えた最強のXXもどきを作りたい。

o_cop275.jpg

o_cop290.jpg




//OLED_SSD1331_BITMAP_TEST1_UNO


//ヘッダーファイル
#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
#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);


// ビットマップデータ
uint8_t databytes[8] = 

{

0b01100110,
0b10101111,
0b10111111,
0b11011111,

0b01111110,
0b01111110,
0b00111100,
0b00011000

};


//初期化
void setup() {

  // I2Cアドレスは使用するディスプレイに合わせて変更する
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);

}//setup


//メインループ
void loop() {

  // 画面表示をクリア
  display.clearDisplay();

  //ビットマップの表示
  display.drawBitmap(0, 0, databytes, 8, 8,  WHITE);

  // 描画バッファの内容を画面に表示
  display.display();


  delay(1000); //1秒待つ

}//loop





ドロービットマップの中身は、ドットを打っているだけ


void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
                              int16_t w, int16_t h, uint16_t color) {

  int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
  uint8_t b = 0;

  startWrite();
  for (int16_t j = 0; j < h; j++, y++) {
    for (int16_t i = 0; i < w; i++) {
      if (i & 7)
        b <<= 1;
      else
        b = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
      if (b & 0x80)
        writePixel(x + i, y, color);
    }
  }
  endWrite();
}



ssd1306_command1

機能 - コマンドを1文字だけ転送する。


ssd1306_commandList

機能 - コマンドを複数転送する。


begin

機能 - 電源の何か?とI2Cアドレスを指定するし初期化する。


clearDisplay

機能 - バッファーを全てクリアーする。


drawPixel

機能 - ドットを書き込む。
詳細 - x,yとカラー(白、黒、反転)


display

機能 - I2Cを使い、バッファー内のデータを全てSSD1306に転送する。


getPixel

機能 - ドットのオンオフを返す。


getBuffer

機能 - バッファーのアドレスを返す。


invertDisplay

機能 - 全体を反転させる

o_cop604.jpg

o_cop605.jpg


display.invertDisplay(true);   delay(2000);
display.invertDisplay(false);  delay(2000);



dim

機能 - 画面の明度(コンストラクト)を調整する

o_cop606.jpg

o_cop607.jpg


display.dim(true);   delay(2000);
display.dim(false);  delay(2000);



startscrollright
startscrollleft
startscrolldiagright
startscrolldiagleft

機能 - スクロールする。表示効果用

o_cop608.jpg


  display.startscrollright(0x00, 0x07);     delay(2000);
  display.startscrollleft(0x00, 0x07);      delay(2000);
  display.startscrolldiagright(0x00, 0x07); delay(2000);
  display.startscrolldiagleft(0x00, 0x07);  delay(2000);




drawFastVLine
drawFastHLine

機能 - 横、縦専用の線表画

o_cop609.jpg



int16_t ll_x = 10;
int16_t ll_y = 10;
int16_t ll_h = 20;                                 
uint16_t ll_color = 1;


display.drawFastVLine(ll_x, ll_y, ll_h, ll_color);
display.drawFastHLine(ll_x, ll_y, ll_h, ll_color);



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?