Generate sine wave, using analog output

Dependencies:   mbed WaveGen

Dependents:   WaveGen

main.cpp

Committer:
aaronice
Date:
2014-02-07
Revision:
0:fc7729e19c10
Child:
1:6b531bf059e4

File content as of revision 0:fc7729e19c10:


#include "mbed.h"
AnalogOut DA(PTE30);
AnalogIn AD(PTB0);

Serial pc(USBTX, USBRX); // tx, rx

    float da;
    float Amp = 2.0;
    float w = 1.0;
    float pi = 3.14159;
    
void callback() {
    // Note: you need to actually read from the serial to clear the RX interrupt
    //int AA;
    //int ww;
    printf("%c\n", pc.getc());
    wait(0.5);
    pc.printf("Input parameter A(<1.0):\n");
    pc.scanf("%f", &Amp);
    pc.printf("%f\n", Amp);
    //Amp = (float)AA;
    pc.printf("Input parameter w:\n");
    pc.scanf("%f", &w);
    pc.printf("%f\n", w);
    //w = (float)ww;
 }


int main(void) {
        
    
    pc.attach(&callback);
    
    while(1){
        for (float i=0; i<360; i++) {
            da = Amp*(sin(w*i/180*pi)*0.5+0.5);
            DA.write(da);
            
            pc.printf("%f ",da);
            
            
            //AD.read()*3.3;
        }
        //wait(3.0);
    }
}