The program of Musical Instrument in Microgravity ~ Combined All Experiment Video (85% Speed) ~

Dependencies:   mbed

Project introduction slide) https://www.slideshare.net/secret/EFyMJ5f4U6oJbz

Files at this revision

API Documentation at this revision

Comitter:
AkiraK
Date:
Fri Mar 12 02:49:56 2021 +0000
Commit message:
This program make a sound with the change of magnetic field.

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 90918a0a0969 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 12 02:49:56 2021 +0000
@@ -0,0 +1,168 @@
+#define mC 2610.626
+#define mD 2930.665
+#define mE 3290.628
+#define mF 3490.228
+#define mG 3910.995
+#define mA 440.000
+#define mB 493.883
+// viollin: 391.995~4186.009
+// viola: 261.626~2093.005
+// cello: 130.813~1046.502
+// contrabass: 82.407~391.995
+// hape: 61.735~6271.927
+ 
+#include "mbed.h"
+#include "math.h"
+ 
+Ticker timer;
+AnalogOut sp1(p18);
+AnalogIn magSensors[] = {p15,p16,p17,p19,p20};
+float ms[180];
+float m1,m2,m3,m4,m5;
+float freq[3] = {0,0,0};
+ 
+void sound_out(void) {
+//    
+    static float j1=0;
+    static float j2=0;
+    static float j3=0;
+    static float j4=0;
+    static float j5=0;
+    j1=j1+m1;
+    j2=j2+m2;
+    j3=j3+m3;
+    j4=j4+m4;
+    j5=j5+m5;
+    if (j1>180)j1=j1-180;
+    if (j2>180)j2=j2-180;
+    if (j3>180)j3=j3-180;
+    if (j4>180)j4=j4-180;
+    if (j5>180)j5=j5-180;
+    sp1.write((ms[(int)j1]+ms[(int)j2]+ms[(int)j3]+ms[(int)j4]+ms[(int)j5])/5.0);
+}
+ 
+int main() {
+    int i;
+    //setting sincurv
+    for (i=0;i<180;i++) {
+        ms[i]=sin(2*3.1415*(float)i/180.0)/2.0+0.5;
+    }
+    timer.attach_us(&sound_out,100); //10kHz
+    while(true){
+//        printf("magSensors: %f, %f, %f\n", magSensors[0]*3.3 * 1054 + 20, magSensors[1]*3.3, magSensors[2]*3.3);
+
+//        m1 = (magSensors[0]*3.3 * 1149.7 + 391.995) *2*180/10000; //606 violin
+//        m2 = (magSensors[1]*3.3 * 554.96 + 261.626) *2*180/10000; //606  2000 viola
+//        m3 = (magSensors[2]*3.3 * 227.48 + 130.813) *2*180/10000; //  cello
+//        m4 = (magSensors[3]*3.3 * 93.815 + 82.407) *2*180/10000; //606  2000
+//        m5 = (magSensors[4]*3.3 * 1881.876 + 61.735) *2*180/10000; //       
+//        
+        m1 = (magSensors[0]*3.3 * 1881.876 + 61.735) *2*180/10000; //       
+        m2 = (magSensors[1]*3.3 * 1881.876 + 61.735) *2*180/10000; //       
+        m3 = (magSensors[2]*3.3 * 1881.876 + 61.735) *2*180/10000; //       
+        m4 = (magSensors[3]*3.3 * 1881.876 + 61.735) *2*180/10000; //       
+        m5 = (magSensors[4]*3.3 * 1881.876 + 61.735) *2*180/10000; //       
+        
+       // m1 = (sqrt(magSensors[0]*3.3) * 3418.598 + 61.735) *2*180/10000; //       
+//        m2 = (sqrt(magSensors[1]*3.3) * 3418.598 + 61.735) *2*180/10000; //       
+//        m3 = (sqrt(magSensors[2]*3.3) * 3418.598 + 61.735) *2*180/10000; //       
+//        m4 = (sqrt(magSensors[3]*3.3) * 3418.598 + 61.735) *2*180/10000; //       
+//        m5 = (sqrt(magSensors[4]*3.3) * 3418.598 + 61.735) *2*180/10000; //       
+//        printf("%f,%f,%f,%f,%f\n",m1,m2,m3,m4,m5);
+        
+        // Error avoid
+        
+        //for(int i = 0; i < 3; i++) {
+//            m[i] = magSensors[i]*3.3*6054+20;
+//       }
+        //
+        wait(0.00001);
+    }
+    ////ceg
+//    m1=mC*2*180/10000;
+//    m2=mE*2*180/10000;
+//    m3=mG*2*180/10000;
+//    wait(1.0f);
+//    //cfa
+//    m1=mC*2*180/10000;
+//    m2=mF*2*180/10000;
+//    m3=mA*2*180/10000;
+//    wait(1.0f);
+//    //ceg
+//    m1=mC*2*180/10000;
+//    m2=mE*2*180/10000;
+//    m3=mG*2*180/10000;
+//    wait(1.0f);
+//    //bdg
+//    m1=mB*180/10000;
+//    m2=mD*2*180/10000;
+//    m3=mG*2*180/10000;
+//    wait(1.0f);
+//    //ceg
+//    m1=mC*2*180/10000;
+//    m2=mE*2*180/10000;
+//    m3=mG*2*180/10000;
+//    wait(1.0f);
+//    timer.detach();
+//    sp1.write(0.0f);
+//    while (1);
+}
+
+//Ticker timer;
+//AnalogOut sp1(p18); //define analog out pin
+//
+//float ms[180];
+//float m1;
+//int counter = 0;
+//
+//void sound_out(void) {
+//    static float j = 0;
+//    j = j + m1;
+//    if(j > 180) j = j - 180;
+//    sp1.write(ms[(int)j]);
+//    counter++;
+//    if(counter > 500000) {
+//        timer.detach();
+//        }
+//}
+//
+//int main() {
+//    float mm[] = {mC,mD,mE,mF,mG,mA,mB};   //sound scale
+//    //setting sinecurv
+//    for(int i = 0; i < 180; i++) {
+//        ms[i] = sin(2*3.1415*(float)i/180.0)/2.0+0.5;
+//    }
+//    
+//    for(int i = 0; i < sizeof(mm); i++) {
+//        m1 = mm[i]*180/100000;
+//        timer.attach_us(&sound_out,10);
+//        counter = 0;
+//        wait(0.5f);
+//    }
+//    
+//    sp1.write(0.0f);
+//    while(true);
+//}
+//
+//
+//DigitalOut sp1(p5);
+//Ticker timer;   //Initialize timer interrupt
+//
+//int oto = 0;
+//
+//void tick(void)
+//{
+//    sp1.write(oto); //Digital Out
+//    oto=!oto;       //switch flag of digital out
+//}
+//
+//int main()
+//{
+//    float mm [] = {mC,mD,mE,mF,mG,mA,mB};   //sound scale
+//    for(int i = 0; i < sizeof(mm); i++) {
+//        timer.attach(&tick,1.0/mm[i]/2.0);
+//        wait(0.5f);
+//    }
+//    timer.detach();
+//    while(true);
+//}
diff -r 000000000000 -r 90918a0a0969 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 12 02:49:56 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file