plays a fucking annoying sound for 10 seconds and loops.

Dependencies:   mbed

Fork of song_demo_PWM by jim hamblen

Committer:
mganseij
Date:
Wed Oct 28 14:47:31 2015 +0000
Revision:
4:64c31855f0be
Parent:
3:89b8dea1cf17
Child:
5:54dda16baec4
version whatever, this works.

Who changed what in which revision?

UserRevisionLine numberNew 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
mganseij 3:89b8dea1cf17 5 // I apologize in advance for this fucking mess of a code
4180_1 0:b2fdf3770282 6
mganseij 4:64c31855f0be 7 DigitalIn input(A4);
mganseij 3:89b8dea1cf17 8 PwmOut speaker(A5);
mganseij 3:89b8dea1cf17 9 SongPlayer mySpeaker(A5);
mganseij 3:89b8dea1cf17 10 Timer songTimer;
mganseij 3:89b8dea1cf17 11
mganseij 3:89b8dea1cf17 12 bool playbuzz;
4180_1 0:b2fdf3770282 13
mganseij 3:89b8dea1cf17 14 void evalbuzz()
mganseij 3:89b8dea1cf17 15 {
mganseij 3:89b8dea1cf17 16 if(input == 1)
mganseij 3:89b8dea1cf17 17 {
mganseij 3:89b8dea1cf17 18 playbuzz = true;
mganseij 3:89b8dea1cf17 19 }
mganseij 3:89b8dea1cf17 20 else
mganseij 3:89b8dea1cf17 21 {
mganseij 3:89b8dea1cf17 22 playbuzz = false;
mganseij 3:89b8dea1cf17 23 }
mganseij 3:89b8dea1cf17 24 }
4180_1 1:2e6ea42675c7 25
mganseij 3:89b8dea1cf17 26 void buzz()
mganseij 3:89b8dea1cf17 27 {
mganseij 3:89b8dea1cf17 28 for (int i=0; i<26; i=i+2)
mganseij 3:89b8dea1cf17 29 {
mganseij 3:89b8dea1cf17 30 evalbuzz();
mganseij 3:89b8dea1cf17 31 if(playbuzz == true)
mganseij 3:89b8dea1cf17 32 {
mganseij 3:89b8dea1cf17 33 speaker.period(1.0/3800.0);
mganseij 3:89b8dea1cf17 34 speaker = float(i)/50.0;
mganseij 3:89b8dea1cf17 35 wait(.2);
mganseij 3:89b8dea1cf17 36 speaker.period(1.0/4200.0);
mganseij 3:89b8dea1cf17 37 wait(.2);
mganseij 3:89b8dea1cf17 38 }
mganseij 3:89b8dea1cf17 39 else
mganseij 3:89b8dea1cf17 40 {
mganseij 3:89b8dea1cf17 41 songTimer.reset();
mganseij 3:89b8dea1cf17 42 mySpeaker.PlaySong(note,duration);
mganseij 3:89b8dea1cf17 43 break;
mganseij 3:89b8dea1cf17 44 }
mganseij 3:89b8dea1cf17 45 }
mganseij 3:89b8dea1cf17 46
mganseij 3:89b8dea1cf17 47 }
mganseij 3:89b8dea1cf17 48
4180_1 0:b2fdf3770282 49 int main()
4180_1 0:b2fdf3770282 50 {
mganseij 3:89b8dea1cf17 51 songTimer.start();
4180_1 1:2e6ea42675c7 52 mySpeaker.PlaySong(note,duration);
mganseij 3:89b8dea1cf17 53 while(1)
mganseij 3:89b8dea1cf17 54 {
mganseij 3:89b8dea1cf17 55 if(input == 0)
mganseij 3:89b8dea1cf17 56 {
mganseij 3:89b8dea1cf17 57 keepplaying = true;
mganseij 3:89b8dea1cf17 58 }
mganseij 3:89b8dea1cf17 59 else
mganseij 3:89b8dea1cf17 60 {
mganseij 3:89b8dea1cf17 61 keepplaying = false;
mganseij 3:89b8dea1cf17 62 }
mganseij 3:89b8dea1cf17 63 if(input == 1)
mganseij 3:89b8dea1cf17 64 {
mganseij 3:89b8dea1cf17 65 playbuzz = true;
mganseij 3:89b8dea1cf17 66 buzz();
mganseij 3:89b8dea1cf17 67 }
mganseij 3:89b8dea1cf17 68 if(songTimer.read() > 9.2)
mganseij 3:89b8dea1cf17 69 {
mganseij 3:89b8dea1cf17 70 songTimer.reset();
mganseij 3:89b8dea1cf17 71 mySpeaker.PlaySong(note,duration);
mganseij 3:89b8dea1cf17 72 }
4180_1 1:2e6ea42675c7 73 wait(.1);
4180_1 0:b2fdf3770282 74 }
4180_1 0:b2fdf3770282 75 }
4180_1 1:2e6ea42675c7 76