Ciaran O'Malley
/
LAB_2_4_Speaker
Lab exercise 2.4
Diff: main.cpp
- Revision:
- 0:d3690ebbbcd6
- Child:
- 1:54ad620bcc3d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jun 20 11:14:10 2020 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" +DigitalIn fire(p14); +PwmOut spkr(p26); +AnalogIn pot1(p19); +int main() +{ + //set loop var + float starti = 500.0; + float endi = 3000.0; + float stepi = 50.0; + + + + while (1) { + for (float i=starti; i<endi; i+=stepi) { + spkr.period(1.0/i); + spkr=0.5; + wait(0.1); + } + spkr=0.0; + + + while(pot1.read() < 0.5) { + starti = 1500.0; + } // this uses the pot to control the program + } +}