sounds

Dependencies:   mbed

Revision:
0:6418a1bc89fe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 09 14:49:11 2014 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+// speaker sound effect demo using PWM hardware output
+PwmOut speaker(p26);
+DigitalIn switch2(p16); //Switch 2
+DigitalIn switch3(p17); //Switch 3
+int main()
+{
+    float i=0.0;
+    while(1)
+    {
+        if(switch2==0&&switch3==0)
+        {
+            speaker=0.0;
+        }
+        else if((switch2==1)&&(switch3==0))
+        {
+            // generate a 500Hz tone using PWM hardware output
+            speaker.period(1.0/500.0); // 500hz period
+            speaker =0.5; //50% duty cycle - max volume
+            wait(.5);
+        }
+        else if((switch3==1)&&(switch2==0))
+        {
+                // two tone police siren effect -  two periods or two frequencies
+                speaker.period(1.0/969.0);
+                speaker =0.25;
+                wait(.5);
+                speaker.period(1.0/500.0);
+                wait(.5);
+    
+        }
+        else if((switch2==1)&&(switch3==1))
+        {
+            while(i<6000.0)
+            {
+                speaker.period(1.0/float(i));
+                speaker=0.25;
+                wait(.1);
+                i+=100;
+                if(i==6000.0)
+                {
+                    i=0.0;
+                }
+                if(switch2==0&&switch3==0)
+                {
+                    break;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file