LoginSignup
1
0

More than 3 years have passed since last update.

Arduino と電磁リレーでダースベイダーのテーマ

Last updated at Posted at 2019-06-17

ArduinoではTone()という関数を使って簡単に音を出す(ピンから矩形波を出す)ことが可能です。
Tone()を連ねることで曲を演奏することができるので、ダースベイダーのテーマのようなメジャーな曲は”arduino darth vader” とかでググるといっぱい出てきます。
たとえばこちら

2019-06-17_142736.png

ピンから矩形波を出しているだけなので、当然電磁リレーも駆動できるのですが、Tone()は通常ピエゾスピーカーから音を出すことを想定して使われているのでリレーには周波数が高すぎます。
そこでオクターブをさげて演奏してみます。

void beep(int note, int duration)
{
  //Play tone on buzzerPin
  tone(buzzerPin, note, duration);

  //Play different LED depending on value of 'counter'

のようにbeep() の中でtone()を呼んでいるので、その前に
3オクターブほど下げてみます。

void beep(int note, int duration)
{
  note >>= 3; // <-
  //Play tone on buzzerPin
  tone(buzzerPin, note, duration);

  //Play different LED depending on value of 'counter'

するといい感じにダースベイダーが出てきそうな音がでます。
2019-06-17_143614.png
もちろんリレーなので音に合わせてLチカもできます。

関連

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