STM32G031で「KEEP DISTANCE」間隔を保持しろと秋月シリアル7セグに出力 (GPIO)(Arduino)


X リセットは、GPIO


1.秋月シリアル7セグの接続
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり


![h_con30.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/06bfff01-e49c-ab99-8fa0-bf52d24f6a16.jpeg)

![h_con31.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/a85f1df2-70af-7079-aa68-521b3b668d2e.jpeg)



![gpio_7seg_keep_d_031_1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/fcd12077-fa7e-c0d0-1324-5f36e5ef7d0b.jpeg)


![o_con527.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/2fac3f43-e871-5219-000a-631b7809d5dc.jpeg)



![resetgpio.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/82f9274b-3470-2e96-ebfd-5e062965de07.jpeg)


![o_con40.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/4de55be4-cc2a-963f-36aa-48b7fe19ed28.jpeg)


![co2_31_bord_k4.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/a4b2c57b-f62f-3a47-beec-957333b30ab6.jpeg)



```c++


#include <Arduino.h>

#define DW   digitalWrite

#define swdclk   PA12 // 6pin
#define swdio    PA11 // 5pin
#define en       PA0  // 4pin

char seg[32] = {
   0x00 , //0 @ -> ' '
   0x77 , //1 A  o
   0x7c , //2 B     　combined use "6"
   0x39 , //3 C
   0x5e , //4 D
   0x79 , //5 E  o
   0x71 , //6 F
   0x3d , //7 G

   0x76 , //8 H  o
   0x06 , //9 I    　combined use "1"
   0x1e , //10 J
   0x75 , //11 K 
   0x38 , //12 L  o
   0x15 , //13 M
   0x37 , //14 N  o
   0x3f , //15 O  o　combined use "0"

   0x73  , //16 P
   0x67  , //17 Q　combined use "9"
   0x50  , //18 R
   0x6d  , //19 S　combined use "5"
   0x78  , //20 T
   0x3e  , //21 U
   0x1c  , //22 V
   0x2a  , //23 W  o
   0x64  , //24 X

   0x6e  , //25 Y
   0x5b  , //26 Z　combined use "2"
   0x4f  , //27 [  --> "3"
   0x66  , //28 \  --> "4"
   0x27  , //29 ]  --> "7"
   0x7f  , //26 ^  --> "8"
   0x08    //31 _
};

//             12345678   12345678   12345678   12345678
char b8[8] = {0b10000000,0b01000000,0b00100000,0b00010000,
              0b00001000,0b00000100,0b00000010,0b00000001 };

void seg1(char v)
{
    for(int jj=0;jj<8;jj++){
        if( (v & b8[jj]) == 0 ){
                DW(swdio,0); //ビットが0
        } else {
                DW(swdio,1); //ビットが1
        }//endif
        DW(swdclk,1);
        DW(swdclk,0);
    }//for
    DW(en,1);
    DW(en,0);
}//seg1

char nn[]={'O','I','Z','[','\\','S','B', ']','^','Q'};

int comma1=0; // コンマ(小数点)の有効フラグ　1で有効　0無効

//7segの一文字出力 nana_seg
int ns_putc(char ch) {

    if(ch == ' ') {
        ch = '@';
    } else if(ch == '.') {
        return(0);
    } else if (ch >= '0' && ch <= '9' ) {
        ch = nn[ch-'0'];
    }

    if( comma1 != 0 ) { comma1 = (0x80); }
    seg1(seg[ch-64] | comma1  );
    comma1 = 0;

    if( ch == ' ' ) {
      //0.3秒待つ
      delay(300); 
    } else {
      //1秒待つ
      delay(1000);
    }

    //戻り値
    return(0);
}//ns_putc

//文字列の表示 nana_seg
int ns_printf(char *str1) {

    //文字の中身がゼロか
    while(*str1){

        //コンマの処理
        comma1=0;
        if( (*(str1+1) ) == '.' ) { comma1=1; }

        //一文字出力
        ns_putc(*str1 ++);

    } //while

    //戻り値
    return(0);
}//ns_printf

//初期化
void setup() {

  delay(3000); //not Delete

  //7セグの初期化
  pinMode(swdclk,OUTPUT);
  pinMode(swdio,OUTPUT);
  pinMode(en,OUTPUT);
  DW(en,0);
  DW(swdclk,0);

}//setup

//ループ
void loop() {

  //間隔を保持しろ
  ns_printf("KE EP   DISTANCE   ");

}//loop



```