![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Lab exercise 2.4
main.cpp@0:d3690ebbbcd6, 2020-06-20 (annotated)
- Committer:
- ciaranom
- Date:
- Sat Jun 20 11:14:10 2020 +0000
- Revision:
- 0:d3690ebbbcd6
- Child:
- 1:54ad620bcc3d
Lab exercise 2.4;
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:d3690ebbbcd6 | 5 | int main() |
ciaranom | 0:d3690ebbbcd6 | 6 | { |
ciaranom | 0:d3690ebbbcd6 | 7 | //set loop var |
ciaranom | 0:d3690ebbbcd6 | 8 | float starti = 500.0; |
ciaranom | 0:d3690ebbbcd6 | 9 | float endi = 3000.0; |
ciaranom | 0:d3690ebbbcd6 | 10 | float stepi = 50.0; |
ciaranom | 0:d3690ebbbcd6 | 11 | |
ciaranom | 0:d3690ebbbcd6 | 12 | |
ciaranom | 0:d3690ebbbcd6 | 13 | |
ciaranom | 0:d3690ebbbcd6 | 14 | while (1) { |
ciaranom | 0:d3690ebbbcd6 | 15 | for (float i=starti; i<endi; i+=stepi) { |
ciaranom | 0:d3690ebbbcd6 | 16 | spkr.period(1.0/i); |
ciaranom | 0:d3690ebbbcd6 | 17 | spkr=0.5; |
ciaranom | 0:d3690ebbbcd6 | 18 | wait(0.1); |
ciaranom | 0:d3690ebbbcd6 | 19 | } |
ciaranom | 0:d3690ebbbcd6 | 20 | spkr=0.0; |
ciaranom | 0:d3690ebbbcd6 | 21 | |
ciaranom | 0:d3690ebbbcd6 | 22 | |
ciaranom | 0:d3690ebbbcd6 | 23 | while(pot1.read() < 0.5) { |
ciaranom | 0:d3690ebbbcd6 | 24 | starti = 1500.0; |
ciaranom | 0:d3690ebbbcd6 | 25 | } // this uses the pot to control the program |
ciaranom | 0:d3690ebbbcd6 | 26 | } |
ciaranom | 0:d3690ebbbcd6 | 27 | } |