First Draft, serial print change based on distance

Revision:
6:18a4dd77057e
Parent:
5:98845ccaaacd
Child:
7:7464fbb0f3e1
--- a/main.cpp	Sat Jan 22 20:06:35 2022 +0000
+++ b/main.cpp	Mon Jan 24 22:35:08 2022 +0000
@@ -14,18 +14,12 @@
     Start.rise(Start_isr);
     Back.mode(PullDown);
     Back.rise(Back_isr);
+    mu.startUpdates();//start mesuring the distance
     
     joystick.init();
     init_display();
-    mu.startUpdates();//start mesuring the distance
     main_menu();
     
-    while(1)
-    {
-    
-        mu.checkDistance();     //call checkDistance() as much as possible, as this is where
-                                //the class checks if dist needs to be called.
-    }
 }
 
 void init_display(){
@@ -38,10 +32,8 @@
         
 void dist(int distance){
 
-    if (distance > 250){
     printf("Safe Distance %dmm\r\n", distance);
     }
-    }
     
 void main_menu(){
     
@@ -105,8 +97,8 @@
             wait(0.15);
             if (Start_flag == 1) {
                 Start_flag = 0;
+                calibrate_object();
             }
-
         }
     }
 }
@@ -199,10 +191,39 @@
                 // or could jump to starting state i.e. state = 0
                 break;  
         }
+        if (Back_flag == 1) {
+            Back_flag = 0;
+            main_menu();}
+            
         ThisThread::sleep_for(200);
         }
         }
         
+void calibrate_object(){
+     
+     int distance; 
+     
+     while(1)
+    {
+      lcd.clear();
+      mu.checkDistance();     //call checkDistance() as much as possible, as this is where
+                                //the class checks if dist needs to be called.
+      printf("Safe Distance %dmm\r\n", distance);
+    
+        char displaydist[14];
+        sprintf(displaydist,"%dmm", distance); // print formatted data to buffer
+        lcd.printString("set object to xxx",0,0);
+        lcd.printString(displaydist,0,3); // display on screen
+        lcd.refresh();
+        
+        if (Back_flag == 1) {
+            Back_flag = 0;
+            main_menu();}
+            
+        wait (1);
+        }
+        }
+        
 void Start_isr()
     {
     Start_flag = 1;