Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:63b2a561690e
- Parent:
- 1:541aec45f686
- Child:
- 3:b2fc5d582f69
--- a/main.cpp Sun Aug 16 12:29:00 2015 +0000 +++ b/main.cpp Sat Aug 22 09:59:29 2015 +0000 @@ -6,8 +6,8 @@ #define SP_ON 0.5 //ピン設定 -PwmOut speaker(dp1); //dp1ピンを出力ピンに設定 -AnalogIn analogInModule(dp13); //dp13ピンをアナログ入力ピンに設定 +PwmOut speaker(A0); //A0ピンを出力ピンに設定 +AnalogIn analogInModule(A5); //A5ピンをアナログ入力ピンに設定 //シリアル通信設定 Serial pc(USBTX, USBRX); @@ -27,7 +27,7 @@ //欲しい入力値の範囲になるよう入力値を調整 //inputVlaueは0.0~1.0の範囲 //このサンプルでは300Hz〜540Hzの周波数になるように変換している。 - outputValue = ((inputValue * 240.0) + 300.0); + outputValue = ((inputValue * 240.0f) + 300.0f); return outputValue; } /*---------------------------------------------------------------------------*/ @@ -38,20 +38,21 @@ while(true) { //入力:センサーなどから入力値を読み取る analogInValue = analogInModule; - pc.printf("analogInValue='%f' :", analogInValue); + //pc.printf("analogInValue='%f' :", analogInValue); + pc.printf("%f,", analogInValue); //analogValue小さい時はスピーカーをオフにする。 - if(analogInValue < 0.05) { + if(analogInValue < 0.05f) { speaker.write(SP_OFF); - pc.printf("OFF\n\r"); + //pc.printf("OFF\n\r"); } else { //処理: tunedValue = tuning(analogInValue); //tuning関数で入力値を調整 - interval = 1.0 / tunedValue; //周波数(Hz)を周期(秒)に変換 + interval = 1.0f / tunedValue; //周波数(Hz)を周期(秒)に変換 //出力設定 speaker.period(interval); speaker.write(SP_ON); //確認用:PCへ現在の各変数の値を送信 - pc.printf("ON tunedValue= '%f' interval= '%f' \n\r", tunedValue, interval); + //pc.printf("ON tunedValue= '%f' interval= '%f' \n\r", tunedValue, interval); } wait(0.1); }