TP1

Dependencies:   mbed

Revision:
10:4276eb0b8d4c
Parent:
9:48e3f6385bff
--- a/main.cpp	Wed Dec 09 10:25:27 2020 +0000
+++ b/main.cpp	Wed Dec 09 11:31:07 2020 +0000
@@ -1,10 +1,28 @@
 #include "mbed.h"
 #include "m3pi.h"
 
+
+#define DO  16.3
+#define DOd 17.3
+#define RE  18.3
+#define REd 19.4
+#define MI 20.5
+#define FA  21.8
+#define FAd 23.1
+#define SOL  24.5
+#define SOLd 26.0
+#define LA  27.5
+#define LAd 29.1
+#define SI  30.8
+
+const char go[] PROGMEM = "L16 cdegreg4";
+
+
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
-
+PwmOut speaker(p26);
 m3pi m3pi;
+float notes[12]= {DO, DOd, RE, REd, MI, FA, FAd, SOL, SOLd, LA, LAd, SI};
 
 Serial pc(USBTX,USBRX);
 
@@ -61,6 +79,18 @@
                 case 'q': fprintf(fp,"qq\n");break;
                 case 's': fprintf(fp,"ss\n");break;
                 case 'd': fprintf(fp,"dd\n");break;
+                case '0': fprintf(fp,"00\n");break;
+                case '1': fprintf(fp,"11\n");break;
+                case '2': fprintf(fp,"22\n");break;
+                case '3': fprintf(fp,"33\n");break;
+                case '4': fprintf(fp,"44\n");break;
+                case '5': fprintf(fp,"55\n");break;
+                case '6': fprintf(fp,"66\n");break;
+                case '7': fprintf(fp,"77\n");break;
+                case '8': fprintf(fp,"88\n");break;
+                case '9': fprintf(fp,"99\n");break;
+                case '-': fprintf(fp,"--\n");break;
+                case '+': fprintf(fp,"++\n");break;
                 
             }
             wait(0.5);
@@ -70,9 +100,16 @@
     fclose(fp);
     }
     
+void PlayNote (float frequency, float volume)
+{
+    speaker.period(1./frequency);
+    speaker=volume;
+}
+    
 void openfile()
 {
     char chaine[2];
+    int octave =2;float volume=0.3;
     FILE *fp = fopen("/local/out.txt", "r");
     if (fp!=NULL)
     {
@@ -100,7 +137,20 @@
                     m3pi.right(0.5);
                     wait(0.5);
                     m3pi.stop();
-                    break;                
+                    break;
+                case '0': PlayNote(notes[0]*pow(2.,octave),volume);break;
+                case '1': PlayNote(notes[1]*pow(2.,octave),volume);break;
+                case '2': PlayNote(notes[2]*pow(2.,octave),volume);break;
+                case '3': PlayNote(notes[3]*pow(2.,octave),volume);break;
+                case '4': PlayNote(notes[4]*pow(2.,octave),volume);break;
+                case '5': PlayNote(notes[5]*pow(2.,octave),volume);break;
+                case '6': PlayNote(notes[6]*pow(2.,octave),volume);break;
+                case '7': PlayNote(notes[7]*pow(2.,octave),volume);break;
+                case '8': PlayNote(notes[8]*pow(2.,octave),volume);break;
+                case '9': PlayNote(notes[9]*pow(2.,octave),volume);break;
+                case '-': PlayNote(notes[10]*pow(2.,octave),volume);break;
+                case '+': PlayNote(notes[11]*pow(2.,octave),volume);break;
+                                
                 }
         }
     }
@@ -115,6 +165,9 @@
     pc.printf("Bonjour \n");
     //USBINTERRUPT.rise(&GetKeyboard);z
     pc.attach(&GetKeyboard, Serial::RxIrq);
+    play_from_program_space(go);
+    while(is_playing());
+
     //flag=0;
     while(1)
     {