plays a fucking annoying sound for 10 seconds and loops.

Dependencies:   mbed

Fork of song_demo_PWM by jim hamblen

main.cpp

Committer:
mganseij
Date:
2015-10-27
Revision:
3:89b8dea1cf17
Parent:
2:2cca82c058fc
Child:
4:64c31855f0be

File content as of revision 3:89b8dea1cf17:

#include "mbed.h"
#include "tones.h"
#include "SongPlayer.h"

// I apologize in advance for this fucking mess of a code

DigitalIn input(D15); 
PwmOut speaker(A5);
SongPlayer mySpeaker(A5);
Timer songTimer;

bool playbuzz;

void evalbuzz()
{
    if(input == 1)
    {
        playbuzz = true;
    }
    else
    {
        playbuzz = false;
    }
}

void buzz()
{
    for (int i=0; i<26; i=i+2)
    {
        evalbuzz();
        if(playbuzz == true)
        {
            speaker.period(1.0/3800.0);
            speaker = float(i)/50.0;
            wait(.2);
            speaker.period(1.0/4200.0);
            wait(.2);
        }
        else
        {
            songTimer.reset();
            mySpeaker.PlaySong(note,duration);
            break;
        }
    }
    
}

int main()
{
    songTimer.start();
    mySpeaker.PlaySong(note,duration);
    while(1)
    {
        if(input == 0)
        {
            keepplaying = true;
        }
        else
        {
            keepplaying = false;
        }
        if(input == 1)
        {
            playbuzz = true;
            buzz();
        }
        if(songTimer.read() > 9.2)
        {
            songTimer.reset();
            mySpeaker.PlaySong(note,duration);
        }
        wait(.1);
    }
}