「液晶128x160」ST7735S(Parallel)を使用してドット絵(Arduino UNO)(ブロック)(VGSZeroを勝手に応援)




x VGSZeroを勝手に応援
x 過去ログを見よ!!!


●　元データを作る 16x20

![o_coq135.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/d6e5c0da-77ba-14fd-5122-549e1e4e44e2.jpeg)


●　画像を16進にする

![o_coq136.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/7904f360-3412-f7d0-ece5-c99e6658261b.jpeg)


●　RGB24bitからRGB16bitに変換 オンラインコンパイラ


```c++



char bitmap[] = {
"0000000000000000000000000000000000000000007F7F7F7F7F7FFE0000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000007F7F7FFEFEFEFE0000FE0000000000000000000000000000000000"
"0000000000000000000000000000000000000000007F7F7F7F7F7F000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000007F7F7F7F7F7F000000000000000000000000000000000000000000"
"000000000000000000FEFEFEFEFEFE7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7FFEFEFEFEFEFE000000000000000000"
"7F7F7F7F7F7F7F7F7F0000007F7F7F0000007F7F7F0000007F7F7F0000007F7F7F0000000000007F7F7F7F7F7F7F7F7F"
"000000000000E0E0E0D0D0D0000000D0D0D0D0D0D0D0D0D0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0000000"
"000000000000000000707070707070000000000000000000000000000000000000707070707070C0C0C0000000000000"
"000000000000000000E0E0E0E0E0E0D0D0D0D0D0D0707070707070707070707070707070C0C0C0000000000000000000"
"000000000000000000000000707070707070707070707070707070707070C0C0C0C0C0C0000000000000000000000000"
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000003F6F9F0000000000000000003F6F9F0000000000000000003F6F9F0000000000000000003F6F9F000000"
"00000000A0A00000A000A0A000000000A0A00000A000A0A000000000A0A00000A000A0A000000000A0A00000A000A0A0"
"00A0A00000A00000A00000A000A0A00000A00000A00000A000A0A00000A00000A00000A000A0A00000A00000A00000A0"
"0000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A0"
"0000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A00000A0"
"0000A00000A00000A00000A00000A00000A00000A00000A08080808080800000A00000A00000A00000A00000A00000A0"
"0000A00000A00000A00000A00000A00000A08080808080808080802020208080800000A00000A00000A00000A00000A0"
"0000A00000A00000A00000A00000A00000A08080802020202020202020208080808080800000A00000A00000A00000A0"
"0000A00000A00000A00000A00000A00000A0808080202020202020A0A0A02020208080800000A00000A00000A00000A0"
}; //bitmap


#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int size_b = ( sizeof bitmap ) - 1;
    int R,G,B;
    int RGB;
    
    printf("\nSTART\n\n");
        for(int ii = 0;ii < (size_b / 6) ;ii++){

#define hex_cov(aa)   ((aa<':')?aa-'0':aa-'A'+10)

        R = (hex_cov(bitmap[ii*6+0])<<4) + hex_cov(bitmap[ii*6+1]);
        R = R >> 3;
        
        G = (hex_cov(bitmap[ii*6+2])<<4) + hex_cov(bitmap[ii*6+3]);
        G = G >> 2;
    
        B = (hex_cov(bitmap[ii*6+4])<<4) + hex_cov(bitmap[ii*6+5]);
        B = B >> 3;
        
        
 
        RGB = (R<<11)+(G<<5)+(B);
          
        //  1234512345612345
        //  6543210987654321
       

        //printf("%c",bitmap[ii*6+0]);
        //printf("%c",bitmap[ii*6+1]);
        //printf("%c",bitmap[ii*6+2]);
        //printf("%c",bitmap[ii*6+3]);
        //printf("%c",bitmap[ii*6+4]);
        //printf("%c",bitmap[ii*6+5]);
        //printf("\n");


        
        //printf("%d-",  R); 
        //printf("%d-",  G);
        //printf("%d\n", B);

        printf("0x%04X,", RGB);
        
        //printf("\n");
        //printf("ppppppp\n");
        
        


    } //for ii
    
    printf("\n\n");
    
}




```



結果

![o_coq137.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/78c33cb9-3e75-aff7-3bfe-fdd8a111762c.jpeg)


プログラム


```c++



//ssd1306_block_bitmap1_UNO_1


//インクルド
#include <Arduino.h>


//定義
//GPIO
#define GPIO_RESET_P  2 //RESET=1
#define GPIO_RS_P    A3 //RS=0
#define GPIO_WR_P     3 //WR=1
#define GPIO_RD_P    A2 //RD=1

#define GPIO_DB7      8
#define GPIO_DB6      7
#define GPIO_DB5      9
#define GPIO_DB4      6
#define GPIO_DB3     A0
#define GPIO_DB2      5
#define GPIO_DB1     A1
#define GPIO_DB0      4

// GPIO A4 I2Cで使用済み
// GPIO A5 I2Cで使用済み

#define GPIO1(s) digitalWrite(GPIO_RESET_P , s)  //RESET
#define GPIO2(s) digitalWrite(GPIO_RS_P    , s)  //A0
#define GPIO3(s) digitalWrite(GPIO_WR_P    , s)  //WR
#define GPIO4(s) digitalWrite(GPIO_RD_P    , s)  //RD

//全体のカラー
int s_color = 0xFFFF; //ハイホワイト

//パターンRAM 16x20ドット
int s_dot[20][16];


//パラレルポートにデータをセットする。
void GPIO_8BIT(int s)
{
  digitalWrite(GPIO_DB7, (s >> 7) & 0x01); //DB7
  digitalWrite(GPIO_DB6, (s >> 6) & 0x01); //DB6
  digitalWrite(GPIO_DB5, (s >> 5) & 0x01); //DB5
  digitalWrite(GPIO_DB4, (s >> 4) & 0x01); //DB4
  digitalWrite(GPIO_DB3, (s >> 3) & 0x01); //DB3
  digitalWrite(GPIO_DB2, (s >> 2) & 0x01); //DB2
  digitalWrite(GPIO_DB1, (s >> 1) & 0x01); //DB1
  digitalWrite(GPIO_DB0,  s       & 0x01); //DB0
} //GPIO_8BIT

//コマンドの書き込み
void LCD_Write_CMD(int a)
{
  GPIO2(0); //A0=0;
  GPIO_8BIT(a);//P1=a; data
  GPIO3(0);//WRB=0;
  GPIO3(1);//WRB=1;
} //LCD_Write_CMD


//データ書き込み
void LCD_Write_Data(int a)
{
  GPIO2(1);//A0=1;
  GPIO_8BIT(a);//P1=a; data
  GPIO3(0);//WRB=0;
  GPIO3(1);//WRB=1;
} //LCD_Write_Data


//液晶の初期化処理
void ATM0177B5_ST7735S_Init(void)
{

  //----------  ST7735S Reset Sequence  --------//

  GPIO1(1);//LCD_RESET=1;

  delay(1); //Delay 1ms

  GPIO1(0);//LCD_RESET=0;

  delay(1); //Delay 1ms

  GPIO1(1);//LCD_RESET=1;

  delay(120); //Delay 120ms

  //----------  ST7735S Reset Sequence  --------//


  LCD_Write_CMD(0x01);//SOFTWARE RESET
  delay(50);

  LCD_Write_CMD(0x11);//SLEEP OUT
  delay(200);

  LCD_Write_CMD(0x29);//display on
  delay(100);

  LCD_Write_CMD(0x3a);//Interface pixel format
  LCD_Write_Data(0x05);//16bit mode
  delay(100);

  LCD_Write_CMD(0x36);//RGB-RGR format
  LCD_Write_Data(0x08);//RGB mode
  delay(100);

  // y,x パターンRAMの初期化
  for (int y = 0; y < 20; y++) {
    for (int x = 0; x < 16; x++) {
      s_dot[y][x] = 0;
    }//for x
  }//for y

} //ATM0177B5_ST7735S_Init


//全体のカラーの変更
void set_color(int color) {

  s_color = color;

}//set_color


//パターンRAMの内容を液晶に転送
void p_ram_refresh() {

  //カラーの上位と下位と一時
  int color_h;
  int color_l;
  int color_vel;

  //画面の書き込み開始
  LCD_Write_CMD(0x2C); //memory write
  GPIO2(1);//A0=1;
  delay(2);

  for (int y = 0; y < 20; y++) {
    for (int k = 0; k < 7; k++) {
      for (int x = 0; x < 16; x++) {
        for (int i = 0; i < 7; i++) {
          color_vel = s_dot[y][x];
          if ( color_vel != 0) {//ドットがあり
            color_h = (color_vel >> 8) & 0xff;
            color_l =  color_vel       & 0xff;
            
            GPIO_8BIT( color_h );//P1=a; data
            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;

            GPIO_8BIT( color_l );//P1=a; data
            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;
          } else {//ドットがなし
            GPIO_8BIT(0x00);//P1=a; data
            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;

            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;
          }//end if
        }//for 8
        GPIO_8BIT(0x00);//P1=a; data

        GPIO3(0);//WRB=0;
        GPIO3(1);//WRB=1;

        GPIO3(0);//WRB=0;
        GPIO3(1);//WRB=1;
      }//for 16
    }//for 7
    for (int i = 0; i < 128; i++) {//空白を1ライン引く
      GPIO3(0);//WRB=0;
      GPIO3(1);//WRB=1;

      GPIO3(0);//WRB=0;
      GPIO3(1);//WRB=1;
    }//for i
  }//for tt

}//p_ram_refresh


//リフレッシュ(画像の再表示)
void refresh() {

  p_ram_refresh();//パターンRAMの反映

}//refresh


//初期化
void setup() {

  //ポートのモード設定
  //アウトプットモード
  pinMode(GPIO_RESET_P, OUTPUT); //REST
  pinMode(GPIO_RS_P,    OUTPUT); //RS
  pinMode(GPIO_WR_P,    OUTPUT); //WR
  pinMode(GPIO_RD_P,    OUTPUT); //RD

  pinMode(GPIO_DB0, OUTPUT); //DB0
  pinMode(GPIO_DB1, OUTPUT); //DB1
  pinMode(GPIO_DB2, OUTPUT); //DB2
  pinMode(GPIO_DB3, OUTPUT); //DB3

  pinMode(GPIO_DB4, OUTPUT); //DB4
  pinMode(GPIO_DB5, OUTPUT); //DB5
  pinMode(GPIO_DB6, OUTPUT); //DB6
  pinMode(GPIO_DB7, OUTPUT); //DB7

  //ポートの初期化
  GPIO4(1);//RD=1
  GPIO3(0);//WR=0
  GPIO2(0);//RS=0
  GPIO1(1);//RESET=1

  delay(500); //0.5秒待つ

  //液晶の初期化処理
  ATM0177B5_ST7735S_Init();

} //setup


int bitbamp1[]={
//   1    2      3       4     5       6     7      8      9      10     11    12     13     14     15     16 
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7BEF,0x7BEF,0xF800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7BEF,0xFFFF,0xF800,0xF800,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7BEF,0x7BEF,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7BEF,0x7BEF,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0xFFFF,0xFFFF,0x7BEF,0x7BEF,0x7BEF,0x7BEF,0x7BEF,0x7BEF,0xFFFF,0xFFFF,0x0000,0x0000,0x0000,
0x7BEF,0x7BEF,0x7BEF,0x0000,0x7BEF,0x0000,0x7BEF,0x0000,0x7BEF,0x0000,0x7BEF,0x0000,0x0000,0x7BEF,0x7BEF,0x7BEF,
0x0000,0x0000,0xE71C,0xD69A,0x0000,0xD69A,0xD69A,0xD69A,0xC618,0xC618,0xC618,0x0000,0xC618,0xC618,0xC618,0x0000,
0x0000,0x0000,0x0000,0x738E,0x738E,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x738E,0x738E,0xC618,0x0000,0x0000,
0x0000,0x0000,0x0000,0xE71C,0xE71C,0xD69A,0xD69A,0x738E,0x738E,0x738E,0x738E,0x738E,0xC618,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x738E,0x738E,0x738E,0x738E,0x738E,0x738E,0xC618,0xC618,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x3B73,0x0000,0x0000,0x0000,0x3B73,0x0000,0x0000,0x0000,0x3B73,0x0000,0x0000,0x0000,0x3B73,0x0000,
0x0000,0x0514,0x0014,0x0514,0x0000,0x0514,0x0014,0x0514,0x0000,0x0514,0x0014,0x0514,0x0000,0x0514,0x0014,0x0514,
0x0514,0x0014,0x0014,0x0014,0x0514,0x0014,0x0014,0x0014,0x0514,0x0014,0x0014,0x0014,0x0514,0x0014,0x0014,0x0014,
0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,
0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,
0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x8410,0x8410,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,
0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x8410,0x8410,0x8410,0x2104,0x8410,0x0014,0x0014,0x0014,0x0014,0x0014,
0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x8410,0x2104,0x2104,0x2104,0x8410,0x8410,0x0014,0x0014,0x0014,0x0014,
0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x8410,0x2104,0x2104,0xA514,0x2104,0x8410,0x0014,0x0014,0x0014,0x0014
};//bitbamp1

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

  int ii=0;
  // y,x パターンRAMの初期化
  for (int y = 0; y < 20; y++) {
    for (int x = 0; x < 16; x++) {
    
        s_dot[y][x] = bitbamp1[ii];
        ii++;
        
    }//for x
  }//for y

  refresh(); //画面の再表示

  delay(3000); //3秒待つ debug

} //loop


```