NXP Group 13 / Mbed 2 deprecated Car3

Dependencies:   camera mbed tsi_sensor

Fork of Car2 by Zach Matthews

Revision:
21:18f2dc256df2
Parent:
20:ebdfeb37309c
Child:
22:9ef4a01e5038
--- a/main.cpp	Tue Apr 11 20:25:51 2017 +0000
+++ b/main.cpp	Tue Apr 11 20:57:17 2017 +0000
@@ -109,35 +109,41 @@
     bool lookForDark = false;
     int darkBlockSize = 0;
     int darkBlocks = 0;
-    int lightGap = 0;
+    int lightGapSize = 0;
+    int minLightGap = 1;
+    int maxLightGap = 55;
+    int minDarkBlock = 4;
+    int maxDarkBlock = 40;
     for(int i = 0; i < 128; i++){
         if(lookForDark){
-            
-            if(true){
-                if(frame[i] < threshold){
-                    darkBlockSize++;
-                    if(darkBlockSize > 4){ //minimum size for a dark block
-                        darkBlocks++;
-                        lookForDark = false;
-                        darkBlockSize = 0;
-                    }
+            if(frame[i] < threshold){
+                darkBlockSize++;
+            }
+            else{
+                if(darkBlockSize > minDarkBlock && darkBlockSize < maxDarkBlock){
+                    darkBlocks++;
+                    lookForDark = false;
+                    darkBlockSize = 0;
+                    lightGapSize = 1;
                 }
-                else if(frame[i] > threshold){
+                else{
                     darkBlockSize = 0;
                 }
             }
-            if(!lookForDark){
-                if(frame[i] > threshold){
-                    lightGap++;
+        }
+        if(!lookForDark){
+            if(frame[i] > threshold){
+                lightGapSize++;
+            }
+            else{
+                if(lightGapSize > minLightGap && lightGapSize < maxLightGap){
+                    lookForDark = true;
+                    minLightGap = 20;
+                    lightGapSize = 0;
+                    darkBlockSize = 1;
                 }
                 else{
-                    if(lightGap > 20 && lightGap < 55){
-                        lookForDark = true;
-                        lightGap = 0;
-                    }
-                    else{
-                        lightGap = 0;
-                    }
+                    lightGapSize = 0;
                 }
             }
         }