老 姚
/
AnalogOut
sin Wave generation by AnalogOut
Revision 0:455b26cfa769, committed 2018-06-22
- Comitter:
- yao6116601
- Date:
- Fri Jun 22 23:12:17 2018 +0000
- Commit message:
- Sin wave generation By analogOut
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 455b26cfa769 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jun 22 23:12:17 2018 +0000 @@ -0,0 +1,24 @@ +#include "mbed.h" +#include "iostream" +DigitalOut myled(PF_14); +AnalogOut aout(PA_4); + +const double pi = 3.141592653589793238462; +const double amplitude = 0.5f; +const double offset = 65535/2; +using namespace std; +int main() { + double rads = 0.0; + uint16_t sample = 0; + cout<<"hello\n"; + printf("Analog Out demo\n"); + while(1) { + // sinewave output + for (int i = 0; i < 360; i++) { + rads = (pi * i) / 180.0f; + sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); + aout.write_u16(sample); + } + } + +}
diff -r 000000000000 -r 455b26cfa769 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Jun 22 23:12:17 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/5aab5a7997ee \ No newline at end of file