スピーカーで音を鳴らす

Dependencies:   mbed

main.cpp

Committer:
hagi_hara
Date:
2015-08-22
Revision:
3:722a88ffb4f7
Parent:
2:44b8465482f9

File content as of revision 3:722a88ffb4f7:

//example_01_speaker
//スピーカーを鳴らすサンプルコード
#include "mbed.h"

#define SP_OFF 0.0
#define SP_ON 0.5

#define mC 261.626 //「ド」の周波数(Hz)


PwmOut speaker(A0);//A0ピンを出力ピンに設定

int main()
{
    //音を鳴らす
    speaker.period(1.0/mC);
    speaker.write(SP_ON);

    //5秒待つ
    wait(5.0);
    
    //音を止める
    speaker.write(SP_OFF);
    
    
    while(true);
}