David Mc Sherry
/
INS_LAB_Q5
Speaker
main.cpp@0:8036f3c2c176, 2021-08-19 (annotated)
- Committer:
- t00214916
- Date:
- Thu Aug 19 20:09:19 2021 +0000
- Revision:
- 0:8036f3c2c176
Speaker
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t00214916 | 0:8036f3c2c176 | 1 | #include "mbed.h" |
t00214916 | 0:8036f3c2c176 | 2 | DigitalIn fire(p14); |
t00214916 | 0:8036f3c2c176 | 3 | PwmOut spkr(p26); |
t00214916 | 0:8036f3c2c176 | 4 | AnalogIn pot1(p19); |
t00214916 | 0:8036f3c2c176 | 5 | float start=2000; // Float values to make it easier for second speaker code |
t00214916 | 0:8036f3c2c176 | 6 | float finish=10000; |
t00214916 | 0:8036f3c2c176 | 7 | float step=200; |
t00214916 | 0:8036f3c2c176 | 8 | |
t00214916 | 0:8036f3c2c176 | 9 | int main() |
t00214916 | 0:8036f3c2c176 | 10 | { |
t00214916 | 0:8036f3c2c176 | 11 | while (1) { |
t00214916 | 0:8036f3c2c176 | 12 | for (float i=start; i<finish; i+=step) { // Same code as original |
t00214916 | 0:8036f3c2c176 | 13 | spkr.period(1.0/i); |
t00214916 | 0:8036f3c2c176 | 14 | spkr=0.5; |
t00214916 | 0:8036f3c2c176 | 15 | wait(0.1); |
t00214916 | 0:8036f3c2c176 | 16 | } |
t00214916 | 0:8036f3c2c176 | 17 | spkr=0.0; |
t00214916 | 0:8036f3c2c176 | 18 | |
t00214916 | 0:8036f3c2c176 | 19 | start += 5000; // The second speaker sequence |
t00214916 | 0:8036f3c2c176 | 20 | if (start >= 5000){ |
t00214916 | 0:8036f3c2c176 | 21 | start = 1000; |
t00214916 | 0:8036f3c2c176 | 22 | } |
t00214916 | 0:8036f3c2c176 | 23 | |
t00214916 | 0:8036f3c2c176 | 24 | |
t00214916 | 0:8036f3c2c176 | 25 | while(pot1.read() < 0.5) {} // this uses the pot to control the program |
t00214916 | 0:8036f3c2c176 | 26 | } |
t00214916 | 0:8036f3c2c176 | 27 | } |