スピーカーで音を鳴らす
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:44b8465482f9
- Parent:
- 1:42c121dda003
- Child:
- 3:722a88ffb4f7
diff -r 42c121dda003 -r 44b8465482f9 main.cpp --- a/main.cpp Sat Aug 15 07:07:09 2015 +0000 +++ b/main.cpp Sat Aug 15 07:22:42 2015 +0000 @@ -1,22 +1,26 @@ +//example_01_speaker //スピーカーを鳴らすサンプルコード #include "mbed.h" -#define mC 261.626 //「ド」の周波数 +#define SP_OFF 0.0 +#define SP_ON 0.5 -//ピン設定 -PwmOut speaker(dp1); +#define mC 261.626 //「ド」の周波数(Hz) + + +PwmOut speaker(dp1);//dp1ピンを出力ピンに設定 int main() { //音を鳴らす speaker.period(1.0/mC); - speaker = 0.5; + speaker.write(SP_ON); //5秒待つ wait(5.0); //音を止める - speaker = 0.0; + speaker.write(SP_OFF); while(true);