スピーカーで音を鳴らす

Dependencies:   mbed

Committer:
hagi_hara
Date:
Sat Aug 15 07:01:04 2015 +0000
Revision:
0:f5bba12ef049
Child:
1:42c121dda003
????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hagi_hara 0:f5bba12ef049 1 //スピーカーを鳴らすサンプルコード
hagi_hara 0:f5bba12ef049 2 #include "mbed.h"
hagi_hara 0:f5bba12ef049 3
hagi_hara 0:f5bba12ef049 4 #define mC 261.626 //「ド」の周波数
hagi_hara 0:f5bba12ef049 5
hagi_hara 0:f5bba12ef049 6 //ピン設定
hagi_hara 0:f5bba12ef049 7 PwmOut speaker(dp18);
hagi_hara 0:f5bba12ef049 8
hagi_hara 0:f5bba12ef049 9 int main()
hagi_hara 0:f5bba12ef049 10 {
hagi_hara 0:f5bba12ef049 11 //音を鳴らす
hagi_hara 0:f5bba12ef049 12 speaker.period(1.0/mC);
hagi_hara 0:f5bba12ef049 13 speaker = 0.5;
hagi_hara 0:f5bba12ef049 14
hagi_hara 0:f5bba12ef049 15 //5秒待つ
hagi_hara 0:f5bba12ef049 16 wait(5.0);
hagi_hara 0:f5bba12ef049 17
hagi_hara 0:f5bba12ef049 18 //音を止める
hagi_hara 0:f5bba12ef049 19 speaker = 0.0;
hagi_hara 0:f5bba12ef049 20
hagi_hara 0:f5bba12ef049 21
hagi_hara 0:f5bba12ef049 22 while(true)
hagi_hara 0:f5bba12ef049 23 }