This is a program that generates a sinusoidal output wave with a frequency determined by the user. A terminal emulator is required to interact with the program.
Diff: main.cpp
- Revision:
- 0:40edabd603cf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 22 19:56:31 2015 +0000 @@ -0,0 +1,41 @@ +#include "mbed.h" +#include <iostream> + +Serial pc(USBTX, USBRX); +AnalogOut Aout(PTE30); +float i,delay,f; +bool flag = 0; + +float brightness = 0.0; + +void delay_change() +{ + Aout = 0; + printf("\n\rPlease enter new frequency: "); + std::cin >> f; + delay = 1/(f*200); + float freq = 1/(delay*200); + printf("\n\rFrequency: %f",freq); + flag = 0; +} + +int main() +{ + printf("\n\rWelcome, please enter a frequency: \n"); + std::cin >> f; + pc.attach(*delay_change); + delay = 1/(f*200); + float freq = 1/(delay*200); + printf("\n\rFrequency: %f",freq); + + while(1) { + for (i=0.01; i<=2; i=i+0.01) { + if (flag == 0) { + printf("\n\rPress ENTER on the keyboard to input a new frequency. \n"); + flag = 1; + } + Aout=0.5+0.5*sin(i*3.14159); + wait(delay); + } + } +} \ No newline at end of file