Zhangcheng Huang
/
sine_HZC
This program is used for generate sine wave
Revision 1:fb7df7817e53, committed 2014-02-15
- Comitter:
- stanislashzc
- Date:
- Sat Feb 15 06:13:37 2014 +0000
- Parent:
- 0:997d793062b4
- Commit message:
- UCLA ee 202a homework1
Changed in this revision
--- a/main.lib Sat Feb 08 22:26:20 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/stanislashzc/code/main/#6048eae7eed6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Feb 15 06:13:37 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/869cf507173a \ No newline at end of file
--- /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