Saw Wave Generator

Dependencies:   mbed

Revision:
0:d51bfc20e42e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 15 13:06:53 2017 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+
+AnalogOut aout(A2);
+
+const int maxAoutValue = 4096;
+const float samplingPeriod = 0.25f / maxAoutValue;
+
+int cnt = 0;
+
+void tick()
+{
+    cnt++;
+    if (cnt == maxAoutValue) {
+        cnt = 0;
+    }
+    aout.write_u16(cnt << 4);
+}
+
+int main()
+{
+    Ticker t;
+    t.attach(&tick, samplingPeriod);
+
+    for (;;) {}
+}