MRJJ / clickers

Dependents:   ROCO104_Buggy BuggyDesign

Revision:
4:595e353826e5
Parent:
3:91541ffdf9a5
Child:
5:e32cc4bf5aac
--- a/clickers.cpp	Tue Mar 17 13:13:46 2020 +0000
+++ b/clickers.cpp	Tue Mar 17 15:22:38 2020 +0000
@@ -3,6 +3,7 @@
 #include "clickers.h"
 #include "UltraSonic.h"
 
+//These externs allow variables and functiones to be used that in another folder/library 
 extern DigitalIn microswitch1;       //Instance of the DigitalIn class called 'microswitch1'
 extern DigitalIn microswitch2;       //Instance of the DigitalIn class called 'microswitch2'
 extern Motor Wheel;
@@ -10,35 +11,29 @@
 extern int mm;
 extern void dist();
 extern bool rStopped, fStopped;
-int countDis = 0;
-void RevStop()
+
+void RevStop()//This function will stop the buggy and change the bool to true to say the buggy has been stopped from going backwards
 {
     if (microswitch1 == true)
     {
-        microswitch1.read();        
-        Wheel.Stop();
-        rStopped = true;
-        dist();
+        microswitch1.read();//Read the state of the microswitch        
+        Wheel.Stop();//Stop wheels
+        rStopped = true;//Change bool state to true 
+        dist();//Check distance
     }
 }
-void FwdStop()
+void FwdStop()//This function will stop the buggy and change the bool to true to say the buggy has been stopped from going forwards
 {
-    dist();
-    if (mm<= 500)
+    if (mm<= 500)//Do the following if the buggy is less than 500mm to the edge of the arena
     {
-        countDis++;
-        dist();
-    }
-    else if (mm<= 500 && countDis > 20)
-    {
-        Wheel.Stop();
-        fStopped = true;
-        dist();
+        Wheel.Stop();//Stop wheels
+        fStopped = true;//Change bool state to true 
+        dist();//Check distance
     }
     else
     {
-        countDis = 0;
-        fStopped = false;  
-        dist();
+
+        fStopped = false; //Keep bool state false
+        dist();//Check distance
     }
 }
\ No newline at end of file