Dependencies:   PinDetect mbed Servo

ding.cpp

Committer:
Rufaida
Date:
2012-06-18
Revision:
0:81f78497df4e

File content as of revision 0:81f78497df4e:

/*including the libarary of the ding*/
#include "ding.h"
/*definitions*/
Ticker rhythm;
DigitalIn button(p20);
AnalogOut piezo(p18);
int i, done=0;
float c;
int sample_count;
const signed short *pos;
signed short Var16s;
int Var32s;
unsigned short Var16us;

/*Function to start the ding sound ticker function*/

void myrhythm (void) {
    if (sample_count) {
        Var16s= *pos;
        pos++;
        Var32s=Var16s;                       //Cast into integer
        Var32s+=32768;                       //Add offset (32768)
        Var16us=(unsigned short)Var32s;      //Cast into unsigned short
        piezo.write_u16(Var16us);            //Write to Analog out
        if (--sample_count==0)
            new_event(ev_Timeout);
    }
}
/*the ticker function*/
void Start_up_sound (void) {
    sample_count=0;
    rhythm.attach_us(&myrhythm,23);
}
void start_ding(void) {
    sample_count= 0x28030;              //The sample number
    pos=ding;

}