![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Lab exercise 2.4
main.cpp
- Committer:
- ciaranom
- Date:
- 2020-07-31
- Revision:
- 1:54ad620bcc3d
- Parent:
- 0:d3690ebbbcd6
File content as of revision 1:54ad620bcc3d:
#include "mbed.h" DigitalIn fire(p14); PwmOut spkr(p26); AnalogIn pot1(p19); int main() { //set loop var 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) { //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 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 } }