Prototyp V2

Dependencies:   PM2_Libary

Branch:
michi
Revision:
75:3831b90a4ae0
Parent:
68:e3fc5ed0bc0e
Child:
76:d1bbdcd54703
--- a/main.cpp	Wed Apr 27 08:48:35 2022 +0200
+++ b/main.cpp	Wed Apr 27 10:43:19 2022 +0200
@@ -123,6 +123,29 @@
     return new_turn_rotation;
 }
 
+
+//simple check if there is an object in proximity
+//returns 0 if there is NO object present
+//returns 1 if there is an object present
+//returns 2 if the distance isn't in the expected range
+int StepDetection(double distance){
+    double d_valueMM = distance;
+    if(d_valueMM >= 4) { 
+        return 0;}
+    if(d_valueMM < 4){ 
+         return 1;}
+    if(d_valueMM < 0 || d_valueMM > 100 ){
+         return 2;}
+    else{
+        return 2;
+    }
+
+}
+/*Example implementation
+ * distanceCM = mapping(analogIn.read()*3.3e3f);
+ * stepDetected = StepDetection(distanceCM);
+*/
+
 // sets the Motor to a specified degree in one rotation 
 // PARAM: end_deg = new position of the arm in degree 0 <= value >=360
 // PARAM: current_rotations = the current rotation of the Motor (Motor.getRotation())
@@ -195,7 +218,8 @@
     while (true)
     {
         ir_distance_mV = 1.0e3f * ir_analog_in.read() * 3.3f;
-        
+        printf("detection: %d\n",StepDetection(mapping(ir_distance_mV)));
+
         switch (ToNextFunction) 
         {