plays a fucking annoying sound for 10 seconds and loops.
Dependencies: mbed
Fork of song_demo_PWM by
main.cpp@7:29dd200668db, 2015-10-29 (annotated)
- Committer:
- mganseij
- Date:
- Thu Oct 29 10:34:57 2015 +0000
- Revision:
- 7:29dd200668db
- Parent:
- 5:54dda16baec4
newest version thingy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:b2fdf3770282 | 1 | #include "mbed.h" |
mganseij | 3:89b8dea1cf17 | 2 | #include "tones.h" |
4180_1 | 1:2e6ea42675c7 | 3 | #include "SongPlayer.h" |
mganseij | 3:89b8dea1cf17 | 4 | // I apologize in advance for this fucking mess of a code |
mganseij | 7:29dd200668db | 5 | // Update: it's slightly less of a mess right now! :D |
4180_1 | 0:b2fdf3770282 | 6 | |
mganseij | 4:64c31855f0be | 7 | DigitalIn input(A4); |
mganseij | 3:89b8dea1cf17 | 8 | SongPlayer mySpeaker(A5); |
mganseij | 3:89b8dea1cf17 | 9 | Timer songTimer; |
mganseij | 7:29dd200668db | 10 | Timer deathTimer; |
mganseij | 7:29dd200668db | 11 | bool deathbool = false; |
mganseij | 3:89b8dea1cf17 | 12 | |
mganseij | 7:29dd200668db | 13 | void death() |
mganseij | 3:89b8dea1cf17 | 14 | { |
mganseij | 7:29dd200668db | 15 | deathTimer.reset(); |
mganseij | 7:29dd200668db | 16 | mySpeaker.PlaySong(note_death,duration_death); |
mganseij | 3:89b8dea1cf17 | 17 | } |
4180_1 | 1:2e6ea42675c7 | 18 | |
mganseij | 3:89b8dea1cf17 | 19 | |
4180_1 | 0:b2fdf3770282 | 20 | int main() |
4180_1 | 0:b2fdf3770282 | 21 | { |
mganseij | 3:89b8dea1cf17 | 22 | songTimer.start(); |
mganseij | 7:29dd200668db | 23 | deathTimer.start(); |
4180_1 | 1:2e6ea42675c7 | 24 | mySpeaker.PlaySong(note,duration); |
mganseij | 3:89b8dea1cf17 | 25 | while(1) |
mganseij | 3:89b8dea1cf17 | 26 | { |
mganseij | 3:89b8dea1cf17 | 27 | if(input == 0) |
mganseij | 3:89b8dea1cf17 | 28 | { |
mganseij | 3:89b8dea1cf17 | 29 | keepplaying = true; |
mganseij | 3:89b8dea1cf17 | 30 | } |
mganseij | 3:89b8dea1cf17 | 31 | else |
mganseij | 3:89b8dea1cf17 | 32 | { |
mganseij | 7:29dd200668db | 33 | //keepplaying = false; commented out for now |
mganseij | 3:89b8dea1cf17 | 34 | } |
mganseij | 7:29dd200668db | 35 | if(input == 1 and deathTimer.read() > 4) |
mganseij | 3:89b8dea1cf17 | 36 | { |
mganseij | 7:29dd200668db | 37 | death(); |
mganseij | 7:29dd200668db | 38 | |
mganseij | 3:89b8dea1cf17 | 39 | } |
mganseij | 7:29dd200668db | 40 | if(songTimer.read() > 15) |
mganseij | 3:89b8dea1cf17 | 41 | { |
mganseij | 3:89b8dea1cf17 | 42 | songTimer.reset(); |
mganseij | 3:89b8dea1cf17 | 43 | mySpeaker.PlaySong(note,duration); |
mganseij | 3:89b8dea1cf17 | 44 | } |
4180_1 | 1:2e6ea42675c7 | 45 | wait(.1); |
4180_1 | 0:b2fdf3770282 | 46 | } |
4180_1 | 0:b2fdf3770282 | 47 | } |
4180_1 | 1:2e6ea42675c7 | 48 |