A simple sinewave generator with adjustable amplitude and frequency over potentiometers.
Dependencies: mbed
Revision 0:ea6a4849f64a, committed 2014-12-18
- Comitter:
- tbjazic
- Date:
- Thu Dec 18 08:39:42 2014 +0000
- Commit message:
- Initial commit.
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 ea6a4849f64a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 18 08:39:42 2014 +0000 @@ -0,0 +1,22 @@ +#include "mbed.h" + +AnalogOut out(p18); +AnalogIn pot1(p19); +AnalogIn pot2(p20); + +int main() { + float A, f, T; // sine peak-to-peak amplitude, frequency and period + float Ts; // sampling time + const float PI = 3.14159265; + int numberOfPoints = 100; + while(1) { + A = pot1; // amplitude in range 0 to 3.3 V + f = 10 + 10 * pot2; // frequency in range 10 to 20 Hz + T = 1/f; + Ts = T / numberOfPoints; + for (int i = 0; i < numberOfPoints; i++) { + out = 0.5 + A/2 * sin(2 * PI * f * i * Ts); + wait(Ts); + } + } +} \ No newline at end of file
diff -r 000000000000 -r ea6a4849f64a mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 18 08:39:42 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file