AD変換の値を音を出力する

Files at this revision

API Documentation at this revision

Comitter:
MrBearing
Date:
Wed Jul 13 06:38:26 2011 +0000
Commit message:

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 90daceb61231 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 13 06:38:26 2011 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+
+#define PI 3.142
+#define AMP 0.8
+
+#define SIGNAL_OUTPUT_FREQ 25//usec
+// coz twice zone of human audibility
+AnalogOut signal(p18);
+AnalogIn adin(p17);
+
+Ticker t_wave;
+
+float freq;
+
+float wave_value;
+void sawtoothWave(){
+    wave_value+=freq*SIGNAL_OUTPUT_FREQ/1000000;
+    if(wave_value > 1.0)
+        wave_value = 0.0;
+    float output = AMP*wave_value;
+    signal = output;
+}
+
+float theata;
+void sinWave(){
+    theata += 2*PI*SIGNAL_OUTPUT_FREQ*freq/1000000;
+    if(theata > 2*PI)
+        theata = 0.0; 
+    float output = AMP*( sin(theata)+0.5 );
+    signal = output;
+}
+
+int main() {
+    wave_value = 0.0;
+    freq = 1000;
+    t_wave.attach_us(&sinWave , SIGNAL_OUTPUT_FREQ);
+    while(1){
+        freq = 5000*adin.read();
+    } 
+}
diff -r 000000000000 -r 90daceb61231 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 13 06:38:26 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912