A simple sinewave generator with adjustable amplitude and frequency over potentiometers.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:ea6a4849f64a
--- /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