このライブラリでは、単音とメロディの出力が可能です。 In this library, you can output a single tone and melody. mbedのpwmOutとDigitalOutを使ってスピーカや圧電ブザーを直接駆動します。 directly drive speaker or buzzer and DigitalOut pwmOut using the mbed. メロディデータは、mbedのローカルにtxtファイルとして保存するか、プログラム中に配列データとして保存してください。 Melody data is either stored in a txt file on the local mbed, save it as a data array in the program.

Dependents:   kitchenTimer_Clock SoundLibraryExample_Melody_ProgramData M3PI_SuiviLigne

Files at this revision

API Documentation at this revision

Comitter:
suupen
Date:
Sun Oct 20 06:00:50 2013 +0000
Parent:
8:71488a68dc58
Child:
14:6e0eac903431
Child:
15:d526205994e9
Commit message:
This sample program supported LPC1114FN28

Changed in this revision

Sound.cpp Show annotated file Show diff for this revision Revisions of this file
Sound.h Show annotated file Show diff for this revision Revisions of this file
--- a/Sound.cpp	Sat Nov 19 08:18:24 2011 +0000
+++ b/Sound.cpp	Sun Oct 20 06:00:50 2013 +0000
@@ -59,7 +59,6 @@
 * time interrupt
 *****************************************/
 void Sound::pulseCheck(void) {
-
 //    uint32_t static C_syuukiKeika = 0;
 //    uint8_t static f_muonSet = 0;           // muon ji no sound_out() syori wo kurikaesu no wo fusegu
 //    uint8_t static F_pwmSet = 0;    // 0:zenhan hansyuuki 1:kohan hansyuuki  wo request
@@ -155,7 +154,8 @@
     uint8_t kaicho;
 
 // oto no frequency                 //    do              re          mi          fa          so          ra          si
-const uint16_t DT_onkaiHzN[3][7] = {//    C1              D1          E1          F1          G1          A1          B1        // frequency (1/1 [Hz]/count)
+//131020const float DT_onkaiHzN[3][7] = {//    C1              D1          E1          F1          G1          A1          B1        // frequency (1/1 [Hz]/count)  //131020
+const float DT_onkaiHzN[3][7] = {//    C1              D1          E1          F1          G1          A1          B1        // frequency (1/1 [Hz]/count)          //131020
                                     {30.8677,        34.6478,    38.8909,    41.2034,    46.2493,    51.9131,    58.2705},    // b
                                     {32.7032,        36.7081,    41.2034,    43.6535,    48.9994,    55.0000,    61.7354},    // nomal
                                     {34.6478,        38.8909,    43.6535,    46.2493,    51.9131,    58.2705,    65.4064},    // #
@@ -183,7 +183,8 @@
                 break;
             default:
                 // enso chu & tugi no hatuon settei)
-                O_sound.syuuki = 1000000 / (DT_onkaiHzN[data.hanon][kaicho] * (pow(2.0, ((double)okutabu - 1))));
+//131020        O_sound.syuuki = 1000000 / (DT_onkaiHzN[data.hanon][kaicho] * (pow(2.0, ((double)okutabu - 1))));           //131020
+                O_sound.syuuki = 1000000 / (uint16_t)(DT_onkaiHzN[data.hanon][kaicho] * (pow(2.0, ((double)okutabu - 1)))); //131020
                 O_sound.envelope = data.envelope * 1000;
                 O_sound.shokichienvelope = data.envelope * 1000;
                 break;
@@ -451,3 +452,4 @@
 
 
 
+
--- a/Sound.h	Sat Nov 19 08:18:24 2011 +0000
+++ b/Sound.h	Sun Oct 20 06:00:50 2013 +0000
@@ -22,10 +22,11 @@
 
 /***********************************************************************/
 /*                                                                     */
-/*    Sound.h                                                       */
+/*    Sound.h                                                          */
 /*                                                                     */
 /*    V0.1 : 2011/11/13                                                */
 /*    V0.2 : 2011/11/19  Added copyright notice                        */ 
+/*    V0.3 : 2013/10/20 LPC1114FN28 taiou                              */ 
 /***********************************************************************/
 #ifndef _SOUND_H
 #define _SOUND_H
@@ -43,7 +44,8 @@
 * #include "mbed.h"
 * #include "Sound.h"       // sound library header
 *
-* Sound sound(p21, p10);      // 1tu me no sound syuturyoku (pwmOut = p21,  digitalOut = p10)
+* <LPC1768>
+* Sound sound(p21, p23);      // 1tu me no sound syuturyoku (pwmOut = p21,  digitalOut = p23)
 *
 *
 * <scematic>
@@ -52,7 +54,20 @@
 *  mbed(p21) -----|R:200ohm|----| |  speaker
 *       pwmOut     --------     | | 
 *                               | |
-*  mbed(p10) -------------------|_|
+*  mbed(p23) -------------------|_|
+*       digitalOut                \
+*
+* <LPC1114FN28>
+* Sound sound(dp1, dp2);      // 1tu me no sound syuturyoku (pwmOut = dp1,  digitalOut = dp2)
+*
+*
+* <scematic>
+*                                  
+*                  --------      _/
+*  mbed(dp1) -----|R:200ohm|----| |  speaker
+*       pwmOut     --------     | | 
+*                               | |
+*  mbed(dp2) -------------------|_|
 *       digitalOut                \
 *
 * //--------------------------------
@@ -208,8 +223,13 @@
     Timer hatuon_jikan;
 
 
-#define Z_pwmSyuuki (1)             // PWM syuuki           (1/1[us]/count)     syokichi = 1
-#define Z_pulseCheckSyuuki (20)     // puls check syuuki    (1/1 [us]/count)    syokichi = 20 (10us ika deha pwm settei ga ijo ni naru)
+
+//131020#define Z_pwmSyuuki (1)             // PWM syuuki           (1/1[us]/count)     syokichi = 1
+//131020#define Z_pulseCheckSyuuki (20)     // puls check syuuki    (1/1 [us]/count)    syokichi = 20 (10us ika deha pwm settei ga ijo ni naru)
+
+// LPC1114FN28 taiou notameni syori wo osokusuru.   //131020
+#define Z_pwmSyuuki (10)             // PWM syuuki           (1/1[us]/count)     syokichi = 10
+#define Z_pulseCheckSyuuki (40)     // puls check syuuki    (1/1 [us]/count)    syokichi = 40 (10us ika deha pwm settei ga ijo ni naru)
 
 
 typedef struct{