sounds

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
christianjaunich
Date:
Thu Oct 09 14:49:11 2014 +0000
Commit message:
Sounds with switches

Changed in this revision

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
diff -r 000000000000 -r 6418a1bc89fe main.cpp
--- /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
diff -r 000000000000 -r 6418a1bc89fe mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 09 14:49:11 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file