For MAX32630FTHR microcontroller: Plays piano notes in Nokia composer format text file placed in the SD card

Dependencies:   USBMSD_BD SDFileSystem max32630fthr USBDevice

Revision:
5:8ba2f1e291b9
Parent:
4:24086b80928e
Child:
6:d4cba969e419
Child:
7:412761dab446
--- a/main.cpp	Fri Jul 19 04:47:38 2019 +0000
+++ b/main.cpp	Fri Jul 19 05:02:18 2019 +0000
@@ -154,7 +154,7 @@
 
     if(current_inputtype == nokiacomposer) {
         //for every [note] slot in [song]
-        for(i=0; i<2048; i++) {
+        for(i=0; i<256; i++) {
             //take the first base 10 integer you see.
             //this initializes songpos ALWAYS. lol.
             candidate_number = strtol(songpos-1,&songpos,10);
@@ -180,7 +180,7 @@
             printf("Character:%c\r\n",*songpos);
             pn_det=0;
             //watch out for sharps
-            if(!(*songpos=='#'||'a'<=*songpos<='z')) {
+            if(!(*songpos=='#'||'a'<=*songpos<='z'||*songpos=='-')) {
                 printf("Found invalid PITCH NAME value [%c] at position %li. Skipping word...\r\n",*songpos,songpos-buffer);
                 //skip to after next whitespace
                 do {
@@ -220,6 +220,9 @@
                 case 'b':
                     pn_det+=11;
                     break;
+                case '-':
+                    pn_det=57;
+                    goto skipoctave;
             }
             //check for invalid character at current position
             //means that character was valid. move on.
@@ -243,6 +246,7 @@
                 i--;
                 continue;
             }
+            skipoctave:
             song[i].pitch = (pitchname)pn_det;
             printf("Entered pitch [%i] into song[%i].pitch\r\n",song[i].pitch,i);
             printf("Final: {%i,%i} at i=%i\r\n",song[i].length,song[i].pitch,i);
@@ -341,7 +345,7 @@
     for(i = 0; 1; i++) {
         switch(song[i].pitch) {
             case rest:
-                wait(song[i].length*SPB);
+                wait((1/(float)song[i].length)*SPB);
                 continue;
             case D2:
                 PlayingFreq = 73;
@@ -513,7 +517,7 @@
                 printf("SONG END. PRESS BUTTON TO RESTART.");
                 while(Button)
                 {
-                    printf("\033[A\033[A\033[A\033[A");
+                    wait_ms(2);
                 }
                 goto restart;
         }