avnish aggarwal
/
Book-PE_09-10_Metronomexx
ok
Fork of Book-PE_09-10_Metronomex by
Diff: main.cpp
- Revision:
- 2:d1d15e8c083f
- Parent:
- 1:733a0de4d34c
- Child:
- 3:0de69a4b8aac
diff -r 733a0de4d34c -r d1d15e8c083f main.cpp --- a/main.cpp Thu Aug 01 23:24:00 2013 +0000 +++ b/main.cpp Wed Oct 16 06:21:06 2013 +0000 @@ -9,7 +9,9 @@ DigitalIn up_button(p15); DigitalIn down_button(p16); DigitalOut redled(LED1); //displays the metronome beat -Ticker beat_rate; //define a Ticker, with name “beat_rate” +Ticker beat_rate; +PwmOut spkr(p26); + void beat(void); float period (1); //metronome period in seconds, inital value 0.5 int rate (60); //metronome rate, initial value 120 @@ -42,8 +44,34 @@ void beat() { //this is the metronome beat beat_rate.attach(&beat, period); //update beat rate at this moment + + // speaker + spkr.period(1.0/5000); + spkr=0.5; + + // led redled = 1; wait(.1); + + // turn off speaker and led redled = 0; + spkr = 0.0; } +#ifdef spkr +DigitalIn fire(p14); +PwmOut spkr(p26); + +int main() +{ + while (1) { + for (float i=2000.0; i<10000.0; i+=100) { + spkr.period(1.0/i); + spkr=0.5; + wait(0.1); + } + spkr=0.0; + while(!fire) {} + } +} +#endif \ No newline at end of file