Arduino UNOとSSD1306にアイテムを回転表示する(drawBitmap)


Arduino UNOとSSD1306にアイテムを回転表示する(drawBitmap)



x 過去ログをみよ

x Adafruit SSD1306 を　インストール
x Adafruit GFX Library を　インストール

x 回路は、Arduinoと同じ

目的
OLEDのテスト

SCL , SCL
SDA , SDA

あいてんどう


★0.96インチ★OLEDモジュール★I2C★ [OLED096UNO-A]

販売価格: 500円(税別)

(税込: 550円)





![o_cop289.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/1a221cb0-2e7f-8e36-df10-350a5bf29721.jpeg)






![o_cop290.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/24e974ab-d98c-bfb5-76ee-4d36651dc94f.jpeg)





![o_cop275.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/d415837a-6b8b-0bd7-dedb-8120764925ad.jpeg)



![kaiten1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/3b7d0e77-9103-a30c-d9ab-07ca5237906b.jpeg)




```c++




//OLED_SSD1306_BITMAP_ROLL_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);


//初期化
void setup() {

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

}//setup


int gop[8][8] = {
    {0,0,0,0,  0,0,0,1}, 
    {0,0,0,0,  0,0,0,0},
    {0,0,0,0,  0,0,0,0}, 
    {0,0,0,1,  1,0,0,0}, 

    {0,0,0,1,  1,0,0,0},
    {0,0,0,0,  0,0,0,0}, 
    {0,0,0,0,  0,0,0,0}, 
    {1,0,0,0,  0,0,0,0}
};


void p_out(unsigned char ttt[]) {
    
  char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = 0;

  cc = cc + (gop[0][ii] * 1   );
  cc = cc + (gop[1][ii] * 2   );
  cc = cc + (gop[2][ii] * 4   );
  cc = cc + (gop[3][ii] * 8   );

  cc = cc + (gop[4][ii] * 16  );
  cc = cc + (gop[5][ii] * 32  );
  cc = cc + (gop[6][ii] * 64  );
  cc = cc + (gop[7][ii] * 128 );

  ttt[ii] = cc;


  }//for
    
}//p_out




void p_0(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[0][ii] = cc & 0x1; cc = cc >> 1;
  gop[1][ii] = cc & 0x1; cc = cc >> 1;
  gop[2][ii] = cc & 0x1; cc = cc >> 1;
  gop[3][ii] = cc & 0x1; cc = cc >> 1;

  gop[4][ii] = cc & 0x1; cc = cc >> 1;
  gop[5][ii] = cc & 0x1; cc = cc >> 1;
  gop[6][ii] = cc & 0x1; cc = cc >> 1;
  gop[7][ii] = cc & 0x1;

  }//for
    
}//p_0

void p_m0(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[7][ii] = cc & 0x1; cc = cc >> 1;
  gop[6][ii] = cc & 0x1; cc = cc >> 1;
  gop[5][ii] = cc & 0x1; cc = cc >> 1;
  gop[4][ii] = cc & 0x1; cc = cc >> 1;

  gop[3][ii] = cc & 0x1; cc = cc >> 1;
  gop[2][ii] = cc & 0x1; cc = cc >> 1;
  gop[1][ii] = cc & 0x1; cc = cc >> 1;
  gop[0][ii] = cc & 0x1;

  }//for
    
}//p_0



void p_90(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[ii][0] = cc & 0x1; cc = cc >> 1;
  gop[ii][1] = cc & 0x1; cc = cc >> 1;
  gop[ii][2] = cc & 0x1; cc = cc >> 1;
  gop[ii][3] = cc & 0x1; cc = cc >> 1;

  gop[ii][4] = cc & 0x1; cc = cc >> 1;
  gop[ii][5] = cc & 0x1; cc = cc >> 1;
  gop[ii][6] = cc & 0x1; cc = cc >> 1;
  gop[ii][7] = cc & 0x1;

  }//for
    
}//p_0



void p_m90(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[7-ii][0] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][1] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][2] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][3] = cc & 0x1; cc = cc >> 1;

  gop[7-ii][4] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][5] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][6] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][7] = cc & 0x1;

  }//for
    
}//p_0



void p_270(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[7-ii][7] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][6] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][5] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][4] = cc & 0x1; cc = cc >> 1;

  gop[7-ii][3] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][2] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][1] = cc & 0x1; cc = cc >> 1;
  gop[7-ii][0] = cc & 0x1;

  }//for
    
}//p_90


void p_m270(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[ii][7] = cc & 0x1; cc = cc >> 1;
  gop[ii][6] = cc & 0x1; cc = cc >> 1;
  gop[ii][5] = cc & 0x1; cc = cc >> 1;
  gop[ii][4] = cc & 0x1; cc = cc >> 1;

  gop[ii][3] = cc & 0x1; cc = cc >> 1;
  gop[ii][2] = cc & 0x1; cc = cc >> 1;
  gop[ii][1] = cc & 0x1; cc = cc >> 1;
  gop[ii][0] = cc & 0x1;

  }//for
    
}//p_0



void p_m180(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[7][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[6][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[5][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[4][7-ii] = cc & 0x1; cc = cc >> 1;

  gop[3][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[2][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[1][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[0][7-ii] = cc & 0x1;

  }//for
    
}//p_0


void p_180(char ttt[]) {
    
   char cc;
    
  for(int ii=0;ii<8;ii++)   { 
    
  cc = ttt[ii];

  gop[0][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[1][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[2][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[3][7-ii] = cc & 0x1; cc = cc >> 1;

  gop[4][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[5][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[6][7-ii] = cc & 0x1; cc = cc >> 1;
  gop[7][7-ii] = cc & 0x1;

  }//for
    
}//p_0


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



// ビットマップデータ
char databytes1[8] = 

{

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

0b01111110,
0b01111110,
0b00111100,
0b00011000

};




                             // 1122
  unsigned char bbh[]         ={255,0,
                                0,0,
                                0,0,
                                0,255}; 


/////////////p0

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

  p_0(databytes1); 
  p_out(bbh);

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

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


  delay(1000); //1秒待つ




////////////p90


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

  p_90(databytes1); 
  p_out(bbh);

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

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


  delay(1000); //1秒待つ



///////////p180


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

  p_180(databytes1); 
  p_out(bbh);

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

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


  delay(1000); //1秒待つ



//////////p270




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

  p_270(databytes1); 
  p_out(bbh);

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

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


  delay(1000); //1秒待つ





}//loop




```