このサンプルプログラムはメロディを演奏するプログラムです。 メロディデータはプログラムコードにデータテーブルとして記憶しています。 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 Nov 20 09:43:45 2011 +0000
Child:
1:aa04f8cd7355
Commit message:
V1.0 2011/11/20

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sound.lib	Sun Nov 20 09:43:45 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/suupen/code/Sound/#71488a68dc58
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Nov 20 09:43:45 2011 +0000
@@ -0,0 +1,82 @@
+//=============================================
+// Sound Library Example Program
+//  This sample program will play a melody
+//  Melody data for this program is set in the program as a data table.(DEMEKIN[])
+// <schematic>
+//
+//                                               /
+//   mbed                 --------------      --/
+//   p21(pwmOut)     -----| R:200[ohm] |-----|  |  speaker
+//                        --------------     |  |
+//                                           |  |
+//   p10(DigitalOut) ------------------------|  |
+//                                            --\
+//                                               \
+//==============================================
+#include "mbed.h"
+#include "Sound.h"
+
+// "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)
+    //   |  |   |    | 
+        {1,0xC5,600,500},     // de
+        {1,0xE5,600,500},     // me
+        {1,0x95,600,500},     // kin
+        {1,0x00,600,500},
+
+        {1,0xC5,600,500},     // de
+        {1,0xE5,600,500},     // me
+        {1,0x95,600,500},     // kin
+        {1,0x00,600,500},
+
+        {1,0xC5,600,500},     // de
+        {1,0xE5,600,500},     // me
+        {1,0x95,600,500},     // kin
+        {1,0x95,600,500},     // no
+        {1,0x95,150,500},     // shi
+        {1,0x00,900,500},
+        {1,0xE5,750,500},     // po
+        {1,0x00,450,500},
+
+        {1,0xC5,600,500},     // de
+        {1,0xE5,600,500},     // me
+        {1,0x95,600,500},     // kin
+        {1,0x00,600,500},
+
+        {1,0xC5,600,500},     // de
+        {1,0xE5,600,500},     // me
+        {1,0x95,600,500},     // kin
+        {1,0x00,600,500},
+
+        {1,0x95,600,500},     // ju
+        {1,0xE5,600,500},     // go
+        {1,0xD5,600,500},     // n
+        {1,0xC5,600,500},     // no
+        {1,0xE5,150,500},     // shi
+        {1,0x00,900,500},
+        {1,0xC5,750,500},     // po
+        {1,0x00,1350,500},
+
+        {1,0xFF,1000,0},    // end
+
+};
+
+Sound sound(p21, p10);  // p21(PwmOut), p10(DigitalOut)
+
+int main() {
+
+    // Specifying the data to play melody
+    sound.sound_enso((Sound::sound_t*)DEMEKIN);
+    
+    while(1) {
+        if(sound.sound_enso() == false){
+            sound.sound_enso(true);
+        }
+       
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Nov 20 09:43:45 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912