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.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
302Instructor
Date:
Thu Jan 22 19:56:31 2015 +0000
Commit message:
1/22/15

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 40edabd603cf main.cpp
--- /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
diff -r 000000000000 -r 40edabd603cf mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jan 22 19:56:31 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file