convertidor digital. analogico

Dependencies:   mbed

Revision:
0:02e65197aa23
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 24 00:14:15 2015 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+
+// The sinewave is created on this pin
+AnalogOut aout(DAC0_OUT);
+
+int main()
+{
+    const double pi = 3.141592653589793238462;
+    const double amplitude = 0.5f;
+    const double offset = 65535/2;
+    double rads = 0.0;
+    uint16_t sample = 0;
+
+    while(1) {
+        // sinewave output
+        for (int i = 0; i < 360; i++) {
+            rads = (pi * i) / 180.0f;
+            sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
+            aout.write_u16(sample);
+        }
+    }
+}