LoginSignup
0
0

More than 1 year has passed since last update.

STM32G031のArduinoでのHT16K33でナイトライダー

Last updated at Posted at 2021-02-26

1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり


#include <Wire.h> //I2C library

//STM32G031J6M6
#define sdaPin PA12    // ArduinoA4
#define sclPin PA11    // ArduinoA5

// I2C address. 
#define HT16K33_add 0x70
#define I2Cadr      0x3e  // 固定


char    data_read[2]; //i2cバッファー
int     ii;           //ループカウンター

//レジスターの初期値
char INIT_com[] = {
  0x21,0x81,0xef
};

//表示器への書き込み
void i2c_HT16K33(char *buff1,int n){
  Wire.beginTransmission(HT16K33_add);
  Wire.write(buff1[0]);
  if(n == 2){
    Wire.write(buff1[1]);
  }
  Wire.endTransmission();
  delay(1);
}//i2c_HT16K33

void setup()
{  
  delay(3000); //not delete

  //Wire.begin(); // initialise the connection //767
  Wire.begin(sdaPin,sclPin); //STM32G031J6M6

  //レジスターの初期化 
  for(ii=0;ii<3;ii++){
    i2c_HT16K33(&INIT_com[ii],1);
  } //for

  //表示データの初期化
  for(ii=0;ii<16;ii++){
    data_read[0]=ii;
    data_read[1]=0x00;
    i2c_HT16K33(data_read,2);
  } //for
} //end setup

void loop()
{
  //ビットシフトでナイトライダー
  for(ii=0;ii<8;ii++){
    data_read[0]=0;       //アドレス
    data_read[1]=(1<<ii); //データ
    i2c_HT16K33(data_read,2);
    delay(1000);
  } //for
}//loop


i2c_HT16K33_031_1.jpg

i2c_HT16K33_031_2.jpg

i2c_HT16K33_031_3.jpg

i2c_HT16K33_031_4.jpg

i2c_HT16K33_031_5.jpg

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