buzzer

Dependencies:   mbed

Revision:
1:f6f3187e44c5
Parent:
0:72ee6ba483f8
--- a/main.cpp	Thu Jun 09 10:12:11 2016 +0000
+++ b/main.cpp	Thu Jun 09 14:15:51 2016 +0000
@@ -1,20 +1,27 @@
 #include "mbed.h"
 PwmOut buzzer(p23);
 
+
 // red light   
-while (flag = 1);
-{
-
-            int main() {
+ float frequency[]= {500,0,500,0,500,0,500,0,500,0} ;//alarm frequency array
 
 
-
-            speaker.period_ms(1);                     //1ms period    1k Hz //
+    float beat[]= {1,1,1,1,1,1,1,1,1,1};  //beat array
+    int
+       main()
+    {
+      while (1) {
+        for (
+            int
+            i=0;
+            i<=9 ;
+            i++) {buzzer.period(1/(frequency[i]));                  // PMW period   1/frequency
+            buzzer=0.5;                                             //50% duty cycle
+            wait(0.5*beat[i]);                                      //hold for beat period
+                }
+    }            
+ }
 
-            speaker = 0.5;                           //50% duty cycle  //
-                        }
-
-}
 
 
 // yellow light
@@ -53,9 +60,9 @@
 
      int main() {
             
-            speaker.period_ms(1);                     //1ms period    1k Hz //
+            buzzer.period_ms(1);                     //1ms period    1k Hz //
 
-            speaker = 0;                           //0% duty cycle  //
+            buzzer = 0;                           //0% duty cycle  //
 
 }
 
@@ -69,12 +76,3 @@
 
 
 
-
-
-
-
-
-
-
-
-