avnish aggarwal
/
Book-PE_09-10_Metronomexx
ok
Fork of Book-PE_09-10_Metronomex by
Revision 3:0de69a4b8aac, committed 2013-10-28
- Comitter:
- avnisha
- Date:
- Mon Oct 28 08:44:02 2013 +0000
- Parent:
- 2:d1d15e8c083f
- Commit message:
- bug relating to int/float
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d1d15e8c083f -r 0de69a4b8aac main.cpp --- a/main.cpp Wed Oct 16 06:21:06 2013 +0000 +++ b/main.cpp Mon Oct 28 08:44:02 2013 +0000 @@ -1,7 +1,6 @@ /*Program Example 9.10: Metronome. Uses Ticker to set beat rate -//BusIn joy(p15,p12,p13,p16); */ #include "mbed.h" #include <stdio.h> @@ -13,8 +12,8 @@ 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 +float period (1); +float rate (60); int main() { pc.printf("\r\n"); @@ -36,8 +35,8 @@ if (rate < 40) //limit the minimum beat rate to 40 rate = 40; period = 60/rate; //calculate the beat period - pc.printf("metronome rate is %i\r", rate); - //pc.printf("metronome period is %f\r\n", period); //optional check + pc.printf("metronome rate is %f\r\n", rate); + pc.printf("metronome period is %f\r\n", period); wait (0.5); } } @@ -58,20 +57,3 @@ 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