Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: camera mbed tsi_sensor
Fork of Car2 by
Diff: main.cpp
- Revision:
- 21:18f2dc256df2
- Parent:
- 20:ebdfeb37309c
- Child:
- 22:9ef4a01e5038
diff -r ebdfeb37309c -r 18f2dc256df2 main.cpp --- 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; } } }