Speaker

Dependencies:   mbed

Revision:
0:8036f3c2c176
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Aug 19 20:09:19 2021 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+DigitalIn fire(p14);
+PwmOut spkr(p26);
+AnalogIn pot1(p19);
+float start=2000;   // Float values to make it easier for second speaker code
+float finish=10000;
+float step=200;
+ 
+int main()
+{
+    while (1) {
+        for (float i=start; i<finish; i+=step) {    // Same code as original
+            spkr.period(1.0/i);
+            spkr=0.5;
+            wait(0.1);
+        }
+        spkr=0.0;
+        
+        start += 5000;      // The second speaker sequence
+        if (start >= 5000){
+            start = 1000;
+            }
+            
+        
+        while(pot1.read() < 0.5) {} // this uses the pot to control the program
+    }
+}
\ No newline at end of file