Ciaran O'Malley
/
LAB_2_4_Speaker
Lab exercise 2.4
Revision 1:54ad620bcc3d, committed 2020-07-31
- Comitter:
- ciaranom
- Date:
- Fri Jul 31 15:33:47 2020 +0000
- Parent:
- 0:d3690ebbbcd6
- Commit message:
- Lab 2.4
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jun 20 11:14:10 2020 +0000 +++ b/main.cpp Fri Jul 31 15:33:47 2020 +0000 @@ -2,25 +2,26 @@ 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; + float starti = 500.0; //starting value + float endi = 3000.0; //final value (actually 1 step beyond final value) + float stepi = 50.0; //step size - while (1) { - for (float i=starti; i<endi; i+=stepi) { - spkr.period(1.0/i); + while (1) { //while loop + for (float i=starti; i<endi; i+=stepi) { //using previously set parameters + spkr.period(1.0/i); spkr=0.5; wait(0.1); } spkr=0.0; - while(pot1.read() < 0.5) { + while(pot1.read() < 0.5) { //While potentiometer is less than 50% of max, plays above sound loop except starting at new patameter (i/1500) instead of initially set parameter (i/500) starti = 1500.0; } // this uses the pot to control the program }