Music-Lab3
Dependencies: mbed
Revision 0:104065487410, committed 2016-10-07
- Comitter:
- ziadeldebri
- Date:
- Fri Oct 07 02:59:28 2016 +0000
- Commit message:
- Simple Music Tones.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 104065487410 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 07 02:59:28 2016 +0000 @@ -0,0 +1,48 @@ +/*************** +*Lab3 ECE111 +****************/ + +#include "mbed.h" + + +AnalogIn pot(PTB0); +PwmOut Speaker(PTE31); +InterruptIn button(PTC12); + + + +int i,mode; + +float freq[] = {2272, 2144, 2016, 1904, 1808, 1696, 1600, 1520, 1424, 1344, 1280, 1200, 1136, 1072,1008, 960, 896, 848, 800, 752, 704, 672,624, 592, 550}; + +float beat[] ={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; + +void flip() { + mode = !mode; +} + + +int main() +{ + mode = 1; + button.rise(&flip); // attach the address of the flip function to the rising edge + while (true) { + + if(mode == 1){ + for (int i = 0; i <=20 ; i++){ + Speaker.period(1/(2*freq[i])); + Speaker = 0.5; + wait (0.4*beat[1]); + if(mode == 0){break;} + } + } + else if (mode == 0){ + Speaker.period(1/(pot*2000+20)); + Speaker = 0.5; + wait (0.4*beat[1]); + + } + + + } +}
diff -r 000000000000 -r 104065487410 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Oct 07 02:59:28 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file