Generate sine wave, using analog output

Dependencies:   mbed WaveGen

Dependents:   WaveGen

Revision:
0:fc7729e19c10
Child:
1:6b531bf059e4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 07 00:27:55 2014 +0000
@@ -0,0 +1,47 @@
+
+#include "mbed.h"
+AnalogOut DA(PTE30);
+AnalogIn AD(PTB0);
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+    float da;
+    float Amp = 2.0;
+    float w = 1.0;
+    float pi = 3.14159;
+    
+void callback() {
+    // Note: you need to actually read from the serial to clear the RX interrupt
+    //int AA;
+    //int ww;
+    printf("%c\n", pc.getc());
+    wait(0.5);
+    pc.printf("Input parameter A(<1.0):\n");
+    pc.scanf("%f", &Amp);
+    pc.printf("%f\n", Amp);
+    //Amp = (float)AA;
+    pc.printf("Input parameter w:\n");
+    pc.scanf("%f", &w);
+    pc.printf("%f\n", w);
+    //w = (float)ww;
+ }
+
+
+int main(void) {
+        
+    
+    pc.attach(&callback);
+    
+    while(1){
+        for (float i=0; i<360; i++) {
+            da = Amp*(sin(w*i/180*pi)*0.5+0.5);
+            DA.write(da);
+            
+            pc.printf("%f ",da);
+            
+            
+            //AD.read()*3.3;
+        }
+        //wait(3.0);
+    }
+}
\ No newline at end of file