STM32G031と7セグで3分タイマー(STM32G031J6M6)


STM32G031で3分タイマー

主要もモジュールは、秋月の約200円の7セグ

赤色７セグメントＬＥＤシリアルドライバモジュール　完成品
[OSL10564-74HC595-R]
通販コード　M-12642
発売日　2017/11/07
メーカーカテゴリ　OptoSupply

[M-12642]　赤色７セグメントＬＥＤシリアルドライバモジュール　完成品　通常在庫商品
1個 ￥215（税込）
https://akizukidenshi.com/catalog/g/gM-12642/
https://akizukidenshi.com/download/ds/akizuki/AE-7SEG-BOARD_a2.pdf

7セグで0から作るより秋月のを買ってね!!
インドの山奥(でんでんむし...)の様な人件費の安いところは、別!!

回路は、こちら
STM32G031J6M6のボードの作り方(STM32G031)
https://qiita.com/caa45040/items/f4120160e62ab5f690be


```c++


#include <Arduino.h>

//*          *****  *****  
//*         *       *    * 
//*         ******  *    *
//*         *       *    *
//*         *       *    *
//********   *****  *****

#define DW   digitalWrite

//#define swdclk   PA14 // 8pin
//#define swdio    PA13 // 7pin
#define swdclk   PA12 // 6pin
#define swdio    PA11 // 5pin
//#define t_led1   PA12 // 6pin
//#define t_led2   PA11 // 5pin
#define en       PA0  // 4pin
#define in7      PB7  // 1pin

char seg[32][8] = {
 { 1,1,1,1,1,1,1,1 }, //0 @ -> ' '
 { 0,0,0,0,0,1,0,1 }, //1 A  o
 { 1,1,0,0,0,0,0,1 }, //2 B     　combined use "6"
 { 0,1,0,1,0,0,1,1 }, //3 C
 { 1,0,1,0,0,0,0,1 }, //4 D
 { 0,1,0,0,0,0,1,1 }, //5 E  o
 { 0,1,0,0,0,1,1,1 }, //6 F
 { 0,1,0,1,0,0,0,1 }, //7 G
 
 { 1,0,0,0,0,1,0,1 }, //8 H  o
 { 1,0,1,1,1,1,0,1 }, //9 I    　combined use "1"
 { 1,0,1,1,0,0,0,1 }, //10 J
 { 0,1,0,0,0,1,0,1 }, //11 K 
 { 1,1,0,1,0,0,1,1 }, //12 L  o
 { 0,1,1,1,0,1,0,1 }, //13 M
 { 0,0,0,1,0,1,0,1 }, //14 N  o
 { 0,0,0,1,0,0,0,1 }, //15 O  o　combined use "0"
 
 { 0,0,0,0,0,1,1,1 }, //16 P
 { 0,0,0,0,1,1,0,1 }, //17 Q　combined use "9"
 { 1,1,1,0,0,1,1,1 }, //18 R
 { 0,1,0,0,1,0,0,1 }, //19 S　combined use "5"
 { 1,1,0,0,0,0,1,1 }, //20 T
 { 1,0,0,1,0,0,0,1 }, //21 U
 { 1,1,1,1,0,0,0,1 }, //22 V
 { 1,0,0,1,1,0,1,1 }, //23 W  o
 { 1,1,0,0,1,1,0,1 }, //24 X
 
 { 1,0,0,0,1,0,0,1 }, //25 Y
 { 0,0,1,0,0,0,1,1 }, //26 Z　combined use "2"
 { 0,0,1,0,1,0,0,1 }, //27 [  --> "3"
 { 1,0,0,0,1,1,0,1 }, //28 \  --> "4"
 { 0,0,0,1,1,1,0,1 }, //29 ]  --> "7"
 { 0,0,0,0,0,0,0,1 }, //26 ^  --> "8"
 { 1,1,1,1,1,0,1,1 }  //31 _
};

int vc;
int ch_chvc(int s)
{
        s = s - 64;
  
        vc =0;
        vc = vc | ((!(seg[s][7])) << 7);
        vc = vc | ((!(seg[s][3])) << 6);
        vc = vc | ((!(seg[s][2])) << 5);
        vc = vc | ((!(seg[s][4])) << 4);
        vc = vc | ((!(seg[s][5])) << 3);
        vc = vc | ((!(seg[s][6])) << 2);
        vc = vc | ((!(seg[s][1])) << 1);
        vc = vc | ((!(seg[s][0])) << 0);

        return(vc);
}

int v;
int rs;
void seg1()
{
    DW(swdio,(v>>7)&1);DW(swdclk,1);DW(swdclk,0); //7
    DW(swdio,(v>>6)&1);DW(swdclk,1);DW(swdclk,0); //6
    DW(swdio,(v>>5)&1);DW(swdclk,1);DW(swdclk,0); //5
    DW(swdio,(v>>4)&1);DW(swdclk,1);DW(swdclk,0); //4
    DW(swdio,(v>>3)&1);DW(swdclk,1);DW(swdclk,0); //3
    DW(swdio,(v>>2)&1);DW(swdclk,1);DW(swdclk,0); //2
    DW(swdio,(v>>1)&1);DW(swdclk,1);DW(swdclk,0); //1
    DW(swdio,(v>>0)&1);DW(swdclk,1);DW(swdclk,0); //0
    DW(swdio,rs);   
    DW(en,1);       delayMicroseconds(40);
    DW(en,0);       
}

void setup() {
  // put your setup code here, to run once:

    delay(3000); //not Delete

    pinMode(swdclk,OUTPUT);
    pinMode(swdio,OUTPUT);
    pinMode(en,OUTPUT);
    pinMode(in7,INPUT_PULLUP);

    DW(en,0);
    DW(swdio,0);
    for(int i=0;i<10;i++){
        DW(swdclk,1);
        delay(15);
        DW(swdclk,0);
        delay(15);
    } //for
}

int ii; //ループカウンター
void loop() {
  // put your main code here, to run repeatedly:

  v=ch_chvc('O');seg1();

  for(ii = 0;ii < 60;ii++){
    delay(1000);
  }

  v=ch_chvc('I');seg1();

  for(ii = 0;ii < 60;ii++){
    delay(1000);
  }

  v=ch_chvc('Z');seg1();

  for(ii = 0;ii < 60;ii++){
    delay(1000);
  }

  v=ch_chvc('[');seg1();

  while(1){} //無限ループ
}


```

![7seg_031_y_1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/a8c1aaf3-df6e-57b4-5b6d-b7541b98e014.jpeg)

![7seg_031_y_2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/7ed4199c-f943-1dcb-5b02-d2f9a6e12143.jpeg)

![7seg_b_g031_1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/5e24ca8b-8e33-d260-2c98-0a781f3da6c9.jpeg)

![7seg_akizu_1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/468b3dbb-a02a-4b19-d2e3-f573f05fe653.jpeg)