piano1-1

Files at this revision

API Documentation at this revision

Comitter:
kosukesuzuki
Date:
Tue Aug 16 08:08:32 2022 +0000
Commit message:
piano

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Tue Aug 16 08:08:32 2022 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 16 08:08:32 2022 +0000
@@ -0,0 +1,109 @@
+#define mC 261.626//ド
+#define mD 293.665//レ
+#define mE 329.628//ミ
+#define mF 349.228//ファ
+#define mG 391.995//ソ
+#define mA 440.000//ラ
+#define mB 493.883//シ
+
+#include "mbed.h"
+
+Serial pc(USBTX,USBRX,9600); //UART
+DigitalOut sp1(A0);
+Ticker sound;
+
+int oto = 0;
+
+void tick(void)
+{
+    sp1.write(oto);
+    oto=!oto;
+}
+
+float so = 0; //sound
+
+int t;
+int ct = 0;
+float n;
+
+float mm[]={mC,mD,mE,mF,mG,mA,mB,mC*2};
+
+int main(){//1
+    pc.printf("setting, Eenter ple \r\n");
+    pc.printf("dt[ms] =");
+    
+    scanf("%f",&n);
+    const float dt = n;
+    pc.printf("\r\n start \r\n");
+    
+    while(1){//2
+        t = 1;
+        char cmd;
+        //pc.printf(" count = %d\r\n",ct);
+        
+        if(pc.readable()){
+             cmd = pc.getc();
+             if(cmd == 'q'){    //ド
+                if(pc.readable())t = pc.getc();
+                so = mm[0]*(float)t;
+                sound.attach(&tick,1.0/so/2.0);
+                wait_us(dt);
+                sound.detach();
+                
+                }else if(cmd == 'w'){   //レ
+                    if(pc.readable())t = pc.getc();
+                    so = mm[1]*(float)t;
+                    sound.attach(&tick,1.0/so/2.0);
+                    wait_us(dt);
+                    sound.detach();
+                    
+                    }else if(cmd == 'e'){   //ミ
+                        if(pc.readable())t = pc.getc();
+                        so = mm[2]*(float)t;
+                        sound.attach(&tick,1.0/so/2.0);
+                        wait_us(dt);
+                        sound.detach();
+                        
+                        }else if(cmd == 't'){   //ファ
+                            if(pc.readable())t = pc.getc();
+                            so = mm[3]*(float)t;
+                            sound.attach(&tick,1.0/so/2.0);
+                            wait_us(dt);
+                            sound.detach();
+                            
+                            }else if(cmd == 'y'){   //ソ
+                                if(pc.readable())t = pc.getc();
+                                so = mm[4]*(float)t;
+                                sound.attach(&tick,1.0/so/2.0);
+                                wait_us(dt);
+                                sound.detach();
+                                
+                                }else if(cmd == 'u'){   //ラ
+                                    if(pc.readable())t = pc.getc();
+                                    so = mm[5]*(float)t;
+                                    sound.attach(&tick,1.0/so/2.0);
+                                    wait_us(dt);
+                                    sound.detach();
+                                    
+                                    }else if(cmd == 'i'){   //シ
+                                        if(pc.readable())t = pc.getc();
+                                        so = mm[6]*(float)t;
+                                        sound.attach(&tick,1.0/so/2.0);
+                                        wait_us(dt);
+                                        sound.detach();
+                                        
+                                        }else if(cmd == 'o'){   //ド
+                                            if(pc.readable())t = pc.getc();
+                                            so = mm[7]*(float)t;
+                                            sound.attach(&tick,1.0/so/2.0);
+                                            wait_us(dt);
+                                            sound.detach();
+                                            
+                                            }else if(cmd == 'k'){
+                                                printf("END");
+                                                //return 0;
+                                                }
+            }
+            ct = ct + 1;
+        }//2
+    }//1
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Tue Aug 16 08:08:32 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9