Aaron Huang
/
WaveGen
Generate sine wave, using analog output
main.cpp
- Committer:
- aaronice
- Date:
- 2014-02-12
- Revision:
- 2:e723d10f745d
- Parent:
- 1:6b531bf059e4
- Child:
- 3:be30774cb93f
File content as of revision 2:e723d10f745d:
#include "mbed.h" AnalogOut DA(PTE30); //AnalogIn AD(PTB1); Serial pc(USBTX, USBRX); // tx, rx float da; float Amp = 1.0; float w = 1.0; float pi = 3.14159; float deltaT = 0.01 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) and press Enter:\n"); pc.scanf("%f", &Amp); pc.printf("%f\n", Amp); //Amp = (float)AA; pc.printf("Input parameter w and press Enter:\n"); pc.scanf("%f", &w); pc.printf("%f\n", w); pc.printf("Continuing...\n"); //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); wait(deltaT) pc.printf("%f ",da); //Monitor Received Analog In //pc.printf("%f ", AD.read()); } //wait(3.0); } }