Music-Lab3

Dependencies:   mbed

main.cpp

Committer:
ziadeldebri
Date:
2016-10-07
Revision:
0:104065487410

File content as of revision 0:104065487410:

/***************
*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]);
           
           }
       
        
    }
}