Simulated fire alarm response, with increasing tempo and lowering tone on each repetition

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
saltire78
Date:
Fri Jul 31 13:05:58 2020 +0000
Commit message:
online posting

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 31 13:05:58 2020 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"   
+
+DigitalIn fire(p14); 
+PwmOut spkr(p26); 
+AnalogIn pot1(p19); 
+
+float freqmin = 2000.0;                                     // initialising the low frequency range
+float freqmax = 10000.0;                                    // initialising the high frequency range
+float freqchange = 100;                                     // initialising the frequency change per tone
+float freqperiod = 1.0;                                     // initialising the output tone
+float speakervol = 0.5;                                     // initialising the PWM output
+float tonelength = 0.3;                                     // initialising the time each tone will hold
+
+int main() 
+{   
+    while (1) {         
+        for (float i=freqmin; i<freqmax; i+=freqchange) {             
+            spkr.period(freqperiod/i);                      // PWM output frequency   
+            spkr=speakervol;                                // output volume
+            wait(tonelength);                               // length of each tone
+        }         
+        spkr=0.0;     
+        freqperiod += 1.0;                                  // tone sound will deepen with each repetition
+        tonelength -= 0.05;                                 // tone sound will shorten with each repetition
+
+        while(pot1.read() < 0.5) {} // this uses the pot to control the program     
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jul 31 13:05:58 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file