Evan Zhang / Mbed 2 deprecated StepperMotorSong4180

Dependencies:   mbed mbed-rtos SDFileSystem11

Revision:
13:24238e0b812b
Parent:
12:04af66705f1c
--- a/main.cpp	Mon May 03 19:22:14 2021 +0000
+++ b/main.cpp	Mon May 03 20:00:01 2021 +0000
@@ -175,6 +175,7 @@
      bool holdNotes = 0; //Stop reading notes file once we have the next note
      bool holdStart = 0; //Stop reading start times once we have parsed the starrt
      bool holdFinish = 0; //Stop reading in finish times
+     bool fullStop = 0; //setting for finishing a song
      pc.baud(115200); //Baud rate used for debugging if needed
      const char * d;  //This is old when I was messing around with this stuff
                     //But im actually not sure if I used the names later, should probably check
@@ -212,7 +213,7 @@
     int playtime = 0;
     motor1timer.start(); //Start the timer
     led3 = 1;
-    while (!feof(fpn)){                        // while not end of file, keep goig
+    while (!fullStop){                        // while not end of file, keep goig
         while(!pause){
             motor1timer.stop();
             m1e = 0;
@@ -230,6 +231,7 @@
            if(c == '!'){
                 fclose(fpn);
                 holdNotes = 1;
+                fullStop = 1;
             }                         
            else if(c == ','){                //If the character is a comma, we have parsed the full note
                stringstream degree(output);
@@ -251,7 +253,7 @@
                 fclose(fpstart);
                 holdStart = 1;
             }
-            if(c == ','){
+            else if(c == ','){
                 d = output.c_str();
                 num_float = std::atof(d);
                 //pc.printf("%f\n", num_float);
@@ -270,7 +272,7 @@
                 fclose(fpfinish);
                 holdFinish = 1;
             }
-        if(c == ','){
+        else if(c == ','){
             d = output.c_str();
             num_float = std::atof(d);
             //pc.printf("%f\n", num_float);
@@ -307,7 +309,7 @@
     if it is time to try and assign it to a motor to be played. If it is not time,
     we are simply going to keep looping until it is time.
     */
-    if(myNote.start <= motor1timer.read()){
+    if(myNote.start <= motor1timer.read() && !fullStop){
             if(motor1stop-.002 < motor1timer.read()) { //Check to see if the motor has stopped playing or is going to stop playing
                 t1.attach(&flip1, .5/midi2freq(myNote.midiNote)); //
                 motor1stop = myNote.stop+motor1timer.read(); //Set the new stop time to be the current time plus the duration of the note
@@ -345,16 +347,17 @@
     motor2stop = 0;
     motor3stop = 0;
     
+    m1e = 0;
+    m2e = 0;
+    m3e = 0;
+    
     motor1timer.stop();
     motor1timer.reset();
     // close all the files before trying reopen
-    pc.printf("attempt to close files\n");
-    fclose(fpn);
-    fclose(fpstart);
-    fclose(fpfinish);
-    pc.printf("files closed");
-    //while(bluehelp() != 5){
-    //    Thread::wait(100);
-    //    }
+    //pc.printf("attempt to close files\n");
+    //pc.printf("files closed");
+    while(bluehelp() != 5){
+        Thread::wait(100);
+        }
     goto start;
 }
\ No newline at end of file