5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ESP8266 - 電圧ブザーでメロディを奏でる

Last updated at Posted at 2016-03-14

ESP8266でメロディを奏でる

ESP-WROOM-02 + 電圧ブザーとArduino IDEで音階を鳴らす方法を備忘録として記録します。

ハードウェア

ESP-WROOM-02のGPIO1に電圧ブザーの出力に設定していますが、他のGPIOでも変わりなく動きます。

ソースコード

melody.ino
#define BEAT 300    // 音の長さを指定
#define SOUNDER 1  // 出力ピン

void setup() {
}

void loop() {
  analogWrite(SOUNDER, 500) ;

  analogWriteFreq(262) ;  // ド
  delay(BEAT) ;
  analogWriteFreq(294) ;  // レ
  delay(BEAT) ;
  analogWriteFreq(330) ;  // ミ
  delay(BEAT) ;
  analogWriteFreq(349) ;  // ファ
  delay(BEAT) ;
  analogWriteFreq(392) ;  // ソ
  delay(BEAT) ;
  analogWriteFreq(440) ;  // ラ
  delay(BEAT) ;
  analogWriteFreq(494) ;  // シ
  delay(BEAT) ;
  analogWriteFreq(523) ;  // ド
  delay(BEAT*2) ;

  analogWrite(SOUNDER, 0) ;
  delay(3000) ;           // 3秒後に繰り返す
}
5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?