1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

音スイッチを作って遊ぶ。(M5NanoC6)

Last updated at Posted at 2025-04-09

いろいろ、注意

  • 過去ログ見てちょんまげ!!!
  • GROVE端子の信号の外側(1)がマイク入力
  • GROVE端子の信号の内側(2)がマイク電源
  • 各自、データシート確認の事
  • 全て秋月で調達

結果

image_original(15).jpg

image_original(16).jpg

プログラム




//SoundLed_1_c6_1


//ヘッダー
#include <Arduino.h>


//初期化
void setup() {

  //シリアルポートの初期化
  //Serial.begin(9600); //debug

  //LEDのGPIO初期化
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);

}//setup


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

  int vo = 0;  //電圧
  int cl = 0;  //L ch
  int i  = 0;  //counter

  //L1
  while (cl < 200) { //ピークを越えたらループから抜ける 好みでピーク値を変える
    for (i = 0; i < 8; i++) { //平均化する
      //センサーの値から電圧に変換(x39.0625/8)
      vo = analogRead(1);         //センサーの値
      //vo = ((vo * 39U) + (vo >> 4)) >> 3; //電圧こと 0~5000 //M5NanoC6
      if (vo < 1650) {vo = 1650;} //マイナス側のカット(マイクだから+-あり)
      vo = vo - 1650;             //中心にする
      cl = cl + vo;
    } //for
    cl = cl / 8;
    //Serial.println(cl); //debug
    cl = cl * 1 + cl >> 0;         //倍率を掛ける(好みで変える)
  } //while

  //LEDの点滅
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100); //100ms待つ
  digitalWrite(LED_BUILTIN, LOW);
  //delay(1000); //1秒待つ

}//loop



1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?