このサンプルプログラムはメロディを演奏するプログラムです。 メロディデータはプログラムコードにデータテーブルとして記憶しています。 This sample program is a program that plays the melody. Melody data is stored as data tables in the program code. =video= {{http://www.youtube.com/watch?v=wX-QUprMvT0}}

Dependencies:   mbed Sound

メロディ出力Library のLPC1114FN28対応

https://www.youtube.com/watch?v=CDjyflSWb4Y&feature=c4-overview&list=UUBKFbjZziYG1M-dKWqTlUwA

LPC1768用に作成したメロディLibraryをLPC1114FN28に対応させました。
PWM周期を1[us]から10[us]にして、メロディ出力のためのタイマー割り込みも20[us]から40[us]にしました。(音質にはさほど影響は無いと感じました)

サンプルプログラムはLPC1768用ですので、LPC1114FN28で使用する場合は、main.cppの30行目をコメントアウトして、31行目を有効にして、コンパイルしてください。

Information

SoundLibraryExample_Melody_ProgramData
main.cpp

30行目 //Sound sound(p21, p23);  // LPC1768 p21(PwmOut), p23(DigitalOut)
31行目 Sound sound(dp1, dp2); // LPC1114FN28 dp1(PwmOut), dp2(DigitalOut)

スピーカはLCP1114FN28のdp1とdp2に接続してください。(とりあえずは電流制限抵抗は無くてもかまいません)

/media/uploads/suupen/lpc1114fn28-------.jpg

Files at this revision

API Documentation at this revision

Comitter:
suupen
Date:
Sun Oct 20 06:02:13 2013 +0000
Parent:
0:f773f5034b8b
Child:
2:fc37c5923b0c
Commit message:
This sample program supported LPC1114FN28
;

Changed in this revision

Sound.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/Sound.lib	Sun Nov 20 09:43:45 2011 +0000
+++ b/Sound.lib	Sun Oct 20 06:02:13 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/suupen/code/Sound/#71488a68dc58
+http://mbed.org/users/suupen/code/Sound/#cd42abff5173
--- a/main.cpp	Sun Nov 20 09:43:45 2011 +0000
+++ b/main.cpp	Sun Oct 20 06:02:13 2013 +0000
@@ -4,26 +4,40 @@
 //  Melody data for this program is set in the program as a data table.(DEMEKIN[])
 // <schematic>
 //
+// <LPC1768>
 //                                               /
 //   mbed                 --------------      --/
 //   p21(pwmOut)     -----| R:200[ohm] |-----|  |  speaker
 //                        --------------     |  |
 //                                           |  |
-//   p10(DigitalOut) ------------------------|  |
+//   p23(DigitalOut) ------------------------|  |
+//                                            --\
+//                                               \
+//
+// <LPC1114FN28>
+//                                               /
+//   mbed                 --------------      --/
+//   db1(pwmOut)     -----| R:200[ohm] |-----|  |  speaker
+//                        --------------     |  |
+//                                           |  |
+//   db2(DigitalOut) ------------------------|  |
 //                                            --\
 //                                               \
 //==============================================
 #include "mbed.h"
 #include "Sound.h"
 
+Sound sound(p21, p23);  // LPC1768 p21(PwmOut), p23(DigitalOut)
+//    Sound sound(dp1, dp2); // LPC1114FN28 dp1(PwmOut), dp2(DigitalOut)
+
 // "demekin no uta" melody data
     const Sound::sound_t DEMEKIN[] =     {
-    //  onkai,hatuon jikan[ms]
-    //   hanon siji 0:b(flat)   1:tujo  2:#(sharp)
-    //   |  C1 - B9 kan deno onkai(Gx ha 9x ni okikae te siji)  0xFF=end data
-    //   |  |   time (1/1[ms]/count)   
-    //   |  |   |    envelope(yoin) (1/1 [ms]/count)
-    //   |  |   |    | 
+        //  onkai,hatuon jikan[ms]
+        //   hanon siji 0:b(flat)   1:tujo  2:#(sharp)
+        //   |  C1 - B9 kan deno onkai(Gx ha 9x ni okikae te siji)  0xFF=end data
+        //   |  |   time (1/1[ms]/count)
+        //   |  |   |    envelope(yoin) (1/1 [ms]/count)
+        //   |  |   |    |
         {1,0xC5,600,500},     // de
         {1,0xE5,600,500},     // me
         {1,0x95,600,500},     // kin
@@ -64,19 +78,18 @@
 
         {1,0xFF,1000,0},    // end
 
-};
+    };
 
-Sound sound(p21, p10);  // p21(PwmOut), p10(DigitalOut)
+   int main() {
 
-int main() {
+        // Specifying the data to play melody
+        sound.sound_enso((Sound::sound_t*)DEMEKIN);
 
-    // Specifying the data to play melody
-    sound.sound_enso((Sound::sound_t*)DEMEKIN);
-    
-    while(1) {
-        if(sound.sound_enso() == false){
-            sound.sound_enso(true);
+        while(1) {
+            if(sound.sound_enso() == false) {
+                sound.sound_enso(true);
+            }
+            wait(10);
         }
-       
     }
-}
+
--- a/mbed.bld	Sun Nov 20 09:43:45 2011 +0000
+++ b/mbed.bld	Sun Oct 20 06:02:13 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file