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 DFPlayerMini
Revision 2:86b8aa72661d, committed 2021-06-18
- Comitter:
 - kohacraft
 - Date:
 - Fri Jun 18 07:03:26 2021 +0000
 - Parent:
 - 1:ecebe54ee6e1
 - Commit message:
 - ver1.0
 
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file | 
--- a/main.cpp	Thu Jun 17 23:48:24 2021 +0000
+++ b/main.cpp	Fri Jun 18 07:03:26 2021 +0000
@@ -10,19 +10,28 @@
 int main() {
     mp3.mp3_set_volume(30); //再生音量を設定する30が最大
 
+    int old_sw = sw;
     while(1)
     {
-        if( sw == 1 )
+        //スイッチが押されたら再生開始
+        if( old_sw == 0 && sw == 1 )
         {
             myled = 1;  //LED点灯
-            mp3.mp3_play(0001); //0001.mp3を再生
-            wait(0.1);
-            
-            //再生が終わるまで待つ
-            while( busy == 0 )
-            {
-                wait(0.1);
-            }
+            mp3.mp3_stop(); //現在再生されている音声を停止
+            wait(0.1); 
+            mp3.mp3_single_play(0001);  //0001.mp3(発車ベル)をループ再生
+            wait(0.1); 
+            old_sw = 1;    //スイッチの状態を保存
+        }
+        
+        //スイッチが離されたら音を止めて次の音を再生
+        if( old_sw == 1 && sw == 0 )
+        {
+            mp3.mp3_stop(); //現在再生されている音声を停止
+            wait(0.1); 
+            mp3.mp3_play(0002); //0002.mp3(発車のアナウンス)を再生  
+            wait(0.1); 
+            old_sw = 0;    //スイッチの状態を保存
         }
         
         //LEDを点滅させる