Zhangcheng Huang
/
sine_HZC
This program is used for generate sine wave
Diff: sine.cpp
- Revision:
- 1:fb7df7817e53
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sine.cpp Sat Feb 15 06:13:37 2014 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" +AnalogOut DA(PTE30); + +Serial pc(USBTX, USBRX); // tx, rx + + float sine; + float A = 1.0; + float w = 1.0; + float pi = 3.14159; + + +void callback() { + printf("%c\n", pc.getc()); + wait(1); + pc.printf("Amplitude A(<=1.0):\n"); + pc.scanf("%f", &A); + pc.printf("%f\n", A); + pc.printf("Angular Rate w:\n"); + pc.scanf("%f", &w); + pc.printf("%f\n", w); + + } + + +int main(void) { + + + pc.attach(&callback); + + while(1){ + for (float i=0; i<(3600); i++) { + + sine = 0.5*A*(sin(w*i/(1800)*pi)+1); + DA.write(sine); + pc.printf("%f ",sine); + wait(0.001); + + } + } +} \ No newline at end of file