James Heavey / Mbed 2 deprecated 3875_DISSERTATION

Dependencies:   mbed 3875_Individualproject

Revision:
68:14f2a5315d88
Parent:
67:f307ff6ec083
Child:
69:d1e941e61507
diff -r f307ff6ec083 -r 14f2a5315d88 main/main.cpp
--- a/main/main.cpp	Mon Jun 01 14:30:56 2020 +0000
+++ b/main/main.cpp	Mon Jun 01 20:34:11 2020 +0000
@@ -47,7 +47,7 @@
     robot.lcd_goto_xy(0,1);
     robot.lcd_print("= start   ", 10);
     
-    robot.play_music(go, 13);
+    robot.play_music(start, 13);
     
     calibrate();
     
@@ -203,7 +203,7 @@
             total_points++;
             node_logic(); // determines what junction type we are at updates the explored (path entered on) and type arrays accordingly
             
-            if(goal_node) { point[total_points] = 100; goal_node = false; }  // 100 will be the indicator for the goal node that we can visit once mapping is complete
+            if(goal_node) { point[total_points] = 100; goal_node = false; goal_sound = true; }  // 100 will be the indicator for the goal node that we can visit once mapping is complete
             else { point[total_points] = total_points; } // numbered 0 -> total_points
             
             coords_x[total_points] = curr_coords[0];
@@ -302,7 +302,7 @@
         }
         
         if ( sensor[0] > SENS_THRESH && sensor[4] > SENS_THRESH && sensor[2] < SENS_THRESH ) {
-            wait(0.05);        // maybe change or replace w something better
+            //wait(0.02);        // maybe change or replace w something better
             robot.scan();
             if ( sensor[0] > SENS_THRESH && sensor[4] > SENS_THRESH && sensor[2] < SENS_THRESH ) {
                 goal = true;
@@ -1046,7 +1046,10 @@
     while (sensor[0] > SENS_THRESH) { robot.scan(); }
     
     robot.spin_left(TURN_SPEED);
-    wait(0.25);
+    
+    while (sensor[0] < SENS_THRESH) { robot.scan(); }
+    
+    while (sensor[0] > SENS_THRESH) { robot.scan(); }
     
     while (sensor[1] < SENS_THRESH) { robot.scan(); }
     
@@ -1062,7 +1065,10 @@
     while (sensor[4] > SENS_THRESH) { robot.scan(); }
     
     robot.spin_right(TURN_SPEED);
-    wait(0.25);
+    
+    while (sensor[4] < SENS_THRESH) { robot.scan(); }
+    
+    while (sensor[4] > SENS_THRESH) { robot.scan(); }
     
     while (sensor[3] < SENS_THRESH) { robot.scan(); }
     
@@ -1071,20 +1077,21 @@
 
 void back() 
 {
-    robot.play_music("ggcc",5);
+    if(goal_sound){
+        robot.play_music("ccgg",5);
+        goal_sound = false;
+    }
+    
+    else{
+        robot.play_music("ggcc",5);
+        //robot.play_music(oops,50);
+    }
     
     leds = 0b1111;
-//    robot.reverse(speed);
-//    wait(0.1);
+
     robot.spin_right(TURN_SPEED);
-    if(loop_check == false) {  // works better for looped
-        wait(0.65);
-    }
-    else {
-        while (sensor[3] < SENS_THRESH) { robot.scan(); }
-        
-        while (sensor[3] > SENS_THRESH) { robot.scan(); }
-    }
+    
+    wait(0.65);
 }
 
 void simplify()
@@ -1219,19 +1226,29 @@
     while(1) {
         
         if( _switch == false ) {
-            //robot.play_music(fugue,10);
+            //robot.play_music(victory,22);
+            robot.play_music(win,100);
             robot.lcd_clear();
             robot.lcd_goto_xy(0,0);
             robot.lcd_print("  ENTER   ", 10);
             robot.lcd_goto_xy(0,1);
             robot.lcd_print("=restart", 10);
+            t_L.start();
             while( button_enter.read() == 1 ) {
+                if(t_L > 9.5) {
+                    t_L.stop();
+                    robot.play_music(win,100);
+                    t_L.reset();
+                    t_L.start();
+                }
                 leds = 0b1001;
                 wait(0.2);
                 leds = 0b0110;
                 wait(0.2);
             }
+            robot.play_music("  ccgg",7);
         } else {
+            robot.play_music(victory,22);
             leds = 0b1001;
             wait(0.2);
             leds = 0b0110;