Analog Out sine wave
Dependencies: LSM9DS1_Library mbed
Diff: main.cpp
- Revision:
- 0:9d458257852d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Feb 27 22:25:09 2017 +0000 @@ -0,0 +1,37 @@ +#include "mbed.h" + +//double CosineInterpolate( +// double y1, double y2, +// double mu) +//{ +// double mu2; +// +// mu2 = (1-cos(mu*PI))/2; +// return(y1*(1-mu2)+y2*mu2); +//} + +AnalogOut scope(p18); + +int main() { + + //double voltOut; +// double logicOut; +// +// while(1) { +// scope = +// } + + const double pi = 3.141592653589793238462; + const double amplitude = 0.5f; + const double offset = 65535/2; + double rad = 0.0; + uint16_t sample = 0; + + while(1) { + for(int i = 0; i < 360; i++){ + rad = (pi * i) / 180.0f; + sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); + aout.write_u16(sample); + } + } +}