Lab exercise 2.4

Dependencies:   mbed C12832

Committer:
ciaranom
Date:
Fri Jul 31 15:33:47 2020 +0000
Revision:
1:54ad620bcc3d
Parent:
0:d3690ebbbcd6
Lab 2.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ciaranom 0:d3690ebbbcd6 1 #include "mbed.h"
ciaranom 0:d3690ebbbcd6 2 DigitalIn fire(p14);
ciaranom 0:d3690ebbbcd6 3 PwmOut spkr(p26);
ciaranom 0:d3690ebbbcd6 4 AnalogIn pot1(p19);
ciaranom 1:54ad620bcc3d 5
ciaranom 0:d3690ebbbcd6 6 int main()
ciaranom 0:d3690ebbbcd6 7 {
ciaranom 0:d3690ebbbcd6 8 //set loop var
ciaranom 1:54ad620bcc3d 9 float starti = 500.0; //starting value
ciaranom 1:54ad620bcc3d 10 float endi = 3000.0; //final value (actually 1 step beyond final value)
ciaranom 1:54ad620bcc3d 11 float stepi = 50.0; //step size
ciaranom 0:d3690ebbbcd6 12
ciaranom 0:d3690ebbbcd6 13
ciaranom 0:d3690ebbbcd6 14
ciaranom 1:54ad620bcc3d 15 while (1) { //while loop
ciaranom 1:54ad620bcc3d 16 for (float i=starti; i<endi; i+=stepi) { //using previously set parameters
ciaranom 1:54ad620bcc3d 17 spkr.period(1.0/i);
ciaranom 0:d3690ebbbcd6 18 spkr=0.5;
ciaranom 0:d3690ebbbcd6 19 wait(0.1);
ciaranom 0:d3690ebbbcd6 20 }
ciaranom 0:d3690ebbbcd6 21 spkr=0.0;
ciaranom 0:d3690ebbbcd6 22
ciaranom 0:d3690ebbbcd6 23
ciaranom 1:54ad620bcc3d 24 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)
ciaranom 0:d3690ebbbcd6 25 starti = 1500.0;
ciaranom 0:d3690ebbbcd6 26 } // this uses the pot to control the program
ciaranom 0:d3690ebbbcd6 27 }
ciaranom 0:d3690ebbbcd6 28 }