![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
detonation sound and timer sound
main.cpp@0:b61d0b826228, 2017-01-23 (annotated)
- Committer:
- jacksonbell20
- Date:
- Mon Jan 23 19:19:04 2017 +0000
- Revision:
- 0:b61d0b826228
functioning detonation and timer sounds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jacksonbell20 | 0:b61d0b826228 | 1 | #include "mbed.h" |
jacksonbell20 | 0:b61d0b826228 | 2 | |
jacksonbell20 | 0:b61d0b826228 | 3 | PwmOut speaker(p21); |
jacksonbell20 | 0:b61d0b826228 | 4 | float frequency = 800; |
jacksonbell20 | 0:b61d0b826228 | 5 | float wait_time = 1.000; |
jacksonbell20 | 0:b61d0b826228 | 6 | InterruptIn boom(p5); |
jacksonbell20 | 0:b61d0b826228 | 7 | void detonation(); |
jacksonbell20 | 0:b61d0b826228 | 8 | |
jacksonbell20 | 0:b61d0b826228 | 9 | int main() |
jacksonbell20 | 0:b61d0b826228 | 10 | { |
jacksonbell20 | 0:b61d0b826228 | 11 | boom.rise(&detonation); |
jacksonbell20 | 0:b61d0b826228 | 12 | while(1) |
jacksonbell20 | 0:b61d0b826228 | 13 | { |
jacksonbell20 | 0:b61d0b826228 | 14 | speaker.period(1.0/(2.0*frequency)); |
jacksonbell20 | 0:b61d0b826228 | 15 | speaker = 0.5; |
jacksonbell20 | 0:b61d0b826228 | 16 | wait(0.15); |
jacksonbell20 | 0:b61d0b826228 | 17 | speaker = 0; |
jacksonbell20 | 0:b61d0b826228 | 18 | wait(0.35); |
jacksonbell20 | 0:b61d0b826228 | 19 | speaker.period(1.0/(2.0*(frequency + 100))); |
jacksonbell20 | 0:b61d0b826228 | 20 | speaker = 0.5; |
jacksonbell20 | 0:b61d0b826228 | 21 | wait(0.15); |
jacksonbell20 | 0:b61d0b826228 | 22 | speaker = 0; |
jacksonbell20 | 0:b61d0b826228 | 23 | wait(wait_time); |
jacksonbell20 | 0:b61d0b826228 | 24 | frequency++; |
jacksonbell20 | 0:b61d0b826228 | 25 | wait_time = wait_time - 0.002; |
jacksonbell20 | 0:b61d0b826228 | 26 | } |
jacksonbell20 | 0:b61d0b826228 | 27 | } |
jacksonbell20 | 0:b61d0b826228 | 28 | |
jacksonbell20 | 0:b61d0b826228 | 29 | void detonation() |
jacksonbell20 | 0:b61d0b826228 | 30 | { |
jacksonbell20 | 0:b61d0b826228 | 31 | for(int i = 0; i < 20; i++) |
jacksonbell20 | 0:b61d0b826228 | 32 | { |
jacksonbell20 | 0:b61d0b826228 | 33 | speaker.period(1.0/(2.0*frequency + 100)); |
jacksonbell20 | 0:b61d0b826228 | 34 | speaker = 0.5; |
jacksonbell20 | 0:b61d0b826228 | 35 | wait(0.05); |
jacksonbell20 | 0:b61d0b826228 | 36 | speaker = 0; |
jacksonbell20 | 0:b61d0b826228 | 37 | wait(0.02); |
jacksonbell20 | 0:b61d0b826228 | 38 | speaker.period(1.0/(2.0*(frequency + 100))); |
jacksonbell20 | 0:b61d0b826228 | 39 | speaker = 0.5; |
jacksonbell20 | 0:b61d0b826228 | 40 | wait(0.05); |
jacksonbell20 | 0:b61d0b826228 | 41 | speaker = 0; |
jacksonbell20 | 0:b61d0b826228 | 42 | wait(0.02); |
jacksonbell20 | 0:b61d0b826228 | 43 | } |
jacksonbell20 | 0:b61d0b826228 | 44 | speaker.period(1.0/(2.0*200)); |
jacksonbell20 | 0:b61d0b826228 | 45 | speaker = 0.4; |
jacksonbell20 | 0:b61d0b826228 | 46 | wait(2); |
jacksonbell20 | 0:b61d0b826228 | 47 | |
jacksonbell20 | 0:b61d0b826228 | 48 | } |