![](/media/cache/profiles/e1f5448f160187bcb4c4acaacfb3456c.50x50_q85.jpg)
The program of Musical Instrument in Microgravity ~ Combined All Experiment Video (85% Speed) ~
Project introduction slide) https://www.slideshare.net/secret/EFyMJ5f4U6oJbz
main.cpp
- Committer:
- AkiraK
- Date:
- 2021-03-12
- Revision:
- 0:90918a0a0969
File content as of revision 0:90918a0a0969:
#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); //}