Dependencies:   PinDetect mbed Servo

Committer:
Rufaida
Date:
Mon Jun 18 17:47:17 2012 +0000
Revision:
0:81f78497df4e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rufaida 0:81f78497df4e 1 /*including the libarary of the ding*/
Rufaida 0:81f78497df4e 2 #include "ding.h"
Rufaida 0:81f78497df4e 3 /*definitions*/
Rufaida 0:81f78497df4e 4 Ticker rhythm;
Rufaida 0:81f78497df4e 5 DigitalIn button(p20);
Rufaida 0:81f78497df4e 6 AnalogOut piezo(p18);
Rufaida 0:81f78497df4e 7 int i, done=0;
Rufaida 0:81f78497df4e 8 float c;
Rufaida 0:81f78497df4e 9 int sample_count;
Rufaida 0:81f78497df4e 10 const signed short *pos;
Rufaida 0:81f78497df4e 11 signed short Var16s;
Rufaida 0:81f78497df4e 12 int Var32s;
Rufaida 0:81f78497df4e 13 unsigned short Var16us;
Rufaida 0:81f78497df4e 14
Rufaida 0:81f78497df4e 15 /*Function to start the ding sound ticker function*/
Rufaida 0:81f78497df4e 16
Rufaida 0:81f78497df4e 17 void myrhythm (void) {
Rufaida 0:81f78497df4e 18 if (sample_count) {
Rufaida 0:81f78497df4e 19 Var16s= *pos;
Rufaida 0:81f78497df4e 20 pos++;
Rufaida 0:81f78497df4e 21 Var32s=Var16s; //Cast into integer
Rufaida 0:81f78497df4e 22 Var32s+=32768; //Add offset (32768)
Rufaida 0:81f78497df4e 23 Var16us=(unsigned short)Var32s; //Cast into unsigned short
Rufaida 0:81f78497df4e 24 piezo.write_u16(Var16us); //Write to Analog out
Rufaida 0:81f78497df4e 25 if (--sample_count==0)
Rufaida 0:81f78497df4e 26 new_event(ev_Timeout);
Rufaida 0:81f78497df4e 27 }
Rufaida 0:81f78497df4e 28 }
Rufaida 0:81f78497df4e 29 /*the ticker function*/
Rufaida 0:81f78497df4e 30 void Start_up_sound (void) {
Rufaida 0:81f78497df4e 31 sample_count=0;
Rufaida 0:81f78497df4e 32 rhythm.attach_us(&myrhythm,23);
Rufaida 0:81f78497df4e 33 }
Rufaida 0:81f78497df4e 34 void start_ding(void) {
Rufaida 0:81f78497df4e 35 sample_count= 0x28030; //The sample number
Rufaida 0:81f78497df4e 36 pos=ding;
Rufaida 0:81f78497df4e 37
Rufaida 0:81f78497df4e 38 }