Test program for PwmSound class. Provides tests (demos) for the various sound generating functions in the class. Includes several MML melodies and music clips to test the play() function. Tested on an mbed LPC1768.

Dependencies:   PwmSound mbed

Revision:
0:41640fc98a43
Child:
1:46f098444d0c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 30 22:54:52 2014 +0000
@@ -0,0 +1,146 @@
+/******************************************************************************
+ * File:      main.cpp
+ * Author:    Paul Griffith
+ * Created:   25 Mar 2014
+ * Last Edit: see below
+ * Version:   see below
+ *
+ * Description:
+ * Test program for PwmSound class.
+ *
+ * Copyright (c) 2014 Paul Griffith, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Modifications:
+ * Ver  Date    By  Details
+ * 0.00 25Mar14 PG  File created.
+ * 1.00 30Mar14 PG  Initial release.
+ *
+ ******************************************************************************/
+
+#include "mbed.h"
+#include "PwmSound.h"
+
+PwmSound mySpeaker(p24);    
+Serial pc(USBTX, USBRX);
+
+void badArgs(void);
+void nyi(void);
+void pause(void);
+
+// a simple melody (8 notes)
+
+int melody[8] = {
+    37, 32, 32, 34, 32, 0, 36, 37
+};
+
+int melodyDurations[] = {
+    4, 8, 8, 4, 4, 4, 4, 4
+};
+
+// Dragnet theme (9 notes)
+
+unsigned char dragnet[2+(9*2)+2] = {
+    90,     //tempo
+    PwmSound::NORMAL,   //style
+    29, 5,  31, 16,  32, 8,  0, 8,  29, 5,  31, 16,  32, 8,  29, 8,  35, 3,
+    0, 0    //terminator
+};
+
+int main()
+{
+    int i, n;
+
+    pc.printf("\nPWM Sound Demo 7, %s\n", __DATE__);
+
+    while(1) {
+        pc.printf("0 = 2-tone, 1 = b/g, 2x = melody, 3x = trill, 4x = phone, 5 = Dragnet, 6x-9x = beeps: ");
+        n = pc.getc() - '0';
+        pc.printf("%d", n);
+        if (n == 0) {
+            pc.printf("(= to stop)");
+            mySpeaker.siren(0);
+        }
+        else if (n == 1) {
+            mySpeaker.tone(440.0, 0.0);
+            pc.getc();
+            mySpeaker.stop();
+        } else if (n == 2) {
+            i = pc.getc() - '0';
+            pc.printf("%d", i);
+            mySpeaker.tempo(240);
+            mySpeaker.style( (PwmSound::MusicStyle) (i % 3));
+            for (int i = 0; i < 8; i++) {
+                mySpeaker.note(melody[i], melodyDurations[i]);
+            }           
+        } else if (n == 3) {
+            i = pc.getc() - '0';
+            pc.printf("%d", i);
+            mySpeaker.trill(i);
+        } else if (n == 4) {
+            i = pc.getc() - '0';
+            pc.printf("%d", i);
+            mySpeaker.phone(i);
+        } else if (n == 5) {
+            mySpeaker.tune(dragnet);
+        } else if (n == 6) {
+            i = pc.getc() - '0';
+            pc.printf("%d", i);
+            mySpeaker.bip(i);
+        } else if (n == 7) {
+            i = pc.getc() - '0';
+            pc.printf("%d", i);
+            mySpeaker.beep(i);
+        } else if (n == 8) {
+            i = pc.getc() - '0';
+            pc.printf("%d", i);
+            mySpeaker.bleep(i);
+        } else if (n == 9) {
+            i = pc.getc() - '0';
+            pc.printf("%d", i);
+            mySpeaker.buzz(i);
+        } else if (n == 13) {       //press = to stop a continuous sound
+            mySpeaker.stop();
+        } else {
+            badArgs();            
+        }
+        pc.printf("\n");
+    }   //end of while
+}
+
+//************************
+// Miscellaneous functions
+//************************
+
+void badArgs(void) {
+    pc.printf("?? Bad arguments\n");
+}
+
+void nyi(void) {
+    pc.printf("!! Not yet implemented\n");
+}
+
+void pause(void)
+{
+    pc.printf("Press any key to continue . . .\n");
+    pc.getc();
+}
+
+//END of main.cpp
\ No newline at end of file