Joseph Forde
/
JF_Speaker_1
Speaker_1
main.cpp@0:4d8659571a83, 2020-07-28 (annotated)
- Committer:
- jforde
- Date:
- Tue Jul 28 11:56:43 2020 +0000
- Revision:
- 0:4d8659571a83
Speaker_1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jforde | 0:4d8659571a83 | 1 | #include "mbed.h" //Preprocessor Directives |
jforde | 0:4d8659571a83 | 2 | |
jforde | 0:4d8659571a83 | 3 | DigitalIn fire(p14); // Declarations |
jforde | 0:4d8659571a83 | 4 | PwmOut spkr(p26); |
jforde | 0:4d8659571a83 | 5 | AnalogIn pot1(p19); |
jforde | 0:4d8659571a83 | 6 | float start=2000.0; |
jforde | 0:4d8659571a83 | 7 | float end=10000.0; |
jforde | 0:4d8659571a83 | 8 | float step=100; |
jforde | 0:4d8659571a83 | 9 | |
jforde | 0:4d8659571a83 | 10 | int main() //instructions in main () function |
jforde | 0:4d8659571a83 | 11 | { |
jforde | 0:4d8659571a83 | 12 | while (1) { |
jforde | 0:4d8659571a83 | 13 | {for (float i= start; i<end; i+=step) { |
jforde | 0:4d8659571a83 | 14 | spkr.period(1.0/i); |
jforde | 0:4d8659571a83 | 15 | spkr=0.5; |
jforde | 0:4d8659571a83 | 16 | wait(0.1);} |
jforde | 0:4d8659571a83 | 17 | {for (float i= start; i<end; i+=step) { |
jforde | 0:4d8659571a83 | 18 | spkr.period(1.0/i); |
jforde | 0:4d8659571a83 | 19 | spkr=0.9; |
jforde | 0:4d8659571a83 | 20 | wait(0.3);} |
jforde | 0:4d8659571a83 | 21 | } |
jforde | 0:4d8659571a83 | 22 | spkr=0.0; |
jforde | 0:4d8659571a83 | 23 | while(pot1.read() < 0.5) {} // this uses the pot to control the program |
jforde | 0:4d8659571a83 | 24 | |
jforde | 0:4d8659571a83 | 25 | } |
jforde | 0:4d8659571a83 | 26 | } |
jforde | 0:4d8659571a83 | 27 | } |