MRJJ / Mbed 2 deprecated ROCO104_Buggy

Dependencies:   Movement mbed tunes motor pwm_tone clickers Ultra

Revision:
9:1094da23254d
Parent:
8:f78d756832ad
Child:
12:15272c2ae2ed
diff -r f78d756832ad -r 1094da23254d main.cpp
--- a/main.cpp	Sat Feb 15 12:50:37 2020 +0000
+++ b/main.cpp	Fri Mar 06 16:56:00 2020 +0000
@@ -16,9 +16,9 @@
 */
 #include "mbed.h"
 #include "motor.h"
+#include "UltraSonic.h"
 #include "tunes.h"
 #include "clickers.h"
-#include "ultrasonic.h"
 #define TIME_PERIOD 2             //Constant compiler Values here 2 equates to 2ms or 500Hz base Frequency
 #define DUTY 0.9                  //DUTY of 1.0=100%, 0.4=40% etc.,
 
@@ -34,19 +34,14 @@
                                   //This is Pseudo RS232 over USB the NUCLEO will appear as a COMx Port see device Manager on PC used
                                   //Use PuTTY to monitor check COMx and BAUD rate (115200)
 int mm;
-void dist(int distance)
-{
-    //put code here to happen when the distance is changed
-    printf("%dmm\r\n", distance);
-    mm = distance;
+bool fStopped, rStopped = false;
+void dist(){
+    mm = (int)GetDistance();
 }
-ultrasonic mu(PE_9, PF_15, .1, 1, &dist); //Trigger is PE_9, echo is PF_15. have updates every .1 seconds and a timeout after 1 second, and call dist when the distance changes
-
 int main ()
 {
     pc.baud(9600);               //BAUD Rate to 9600
     pc.printf("ROCO104 Demonstration Robot Buggy Plymouth University 2018/19\n\r");
-    mu.startUpdates();//start mesuring the distance
     Wheel.Period_in_ms(TIME_PERIOD);//Set frequency of the PWMs
     Wheel.Stop();
     
@@ -66,8 +61,10 @@
     
     while(true)                             //Repeat the following forever NB always true!
     {
-        Wheel.Speed(-0.8,-0.8);//Backwards 80%
-        mu.checkDistance();     //call checkDistance() as much as possible
+        dist();
+       
+        ultra_sonic_distance();
         RevStop();
+        FwdStop();
     } // go back to start of while loop
 }  //end of int main()