added stuff

Dependencies:   FRDM-TFC

Fork of TFC-TEST_TXSTATE_TEAM6 by Cody Blakeney

Committer:
anthonylamme
Date:
Mon Apr 06 21:36:56 2015 +0000
Revision:
4:97014a4611c2
Parent:
3:04f91137660a
Child:
5:0c142433cc51
added startstop,main, values for turning and skeleton for left and right turn

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anthonylamme 4:97014a4611c2 1 //made case 2 which is has our main
redxeth 0:6432166d0781 2 #include "mbed.h"
redxeth 0:6432166d0781 3 #include "TFC.h"
anthonylamme 4:97014a4611c2 4 #include <cmath>
redxeth 0:6432166d0781 5
redxeth 0:6432166d0781 6
redxeth 0:6432166d0781 7 //This macro is to maintain compatibility with Codewarrior version of the sample. This version uses the MBED libraries for serial port access
redxeth 0:6432166d0781 8 Serial PC(USBTX,USBRX);
redxeth 0:6432166d0781 9
redxeth 0:6432166d0781 10
redxeth 0:6432166d0781 11
redxeth 0:6432166d0781 12 //This ticker code is used to maintain compability with the Codewarrior version of the sample. This code uses an MBED Ticker for background timing.
redxeth 0:6432166d0781 13
redxeth 0:6432166d0781 14 #define NUM_TFC_TICKERS 4
redxeth 0:6432166d0781 15
redxeth 0:6432166d0781 16 Ticker TFC_TickerObj;
redxeth 0:6432166d0781 17
redxeth 0:6432166d0781 18 volatile uint32_t TFC_Ticker[NUM_TFC_TICKERS];
redxeth 0:6432166d0781 19
redxeth 0:6432166d0781 20 void TFC_TickerUpdate()
redxeth 0:6432166d0781 21 {
redxeth 0:6432166d0781 22 int i;
redxeth 0:6432166d0781 23
redxeth 0:6432166d0781 24 for(i=0; i<NUM_TFC_TICKERS; i++)
redxeth 0:6432166d0781 25 {
redxeth 0:6432166d0781 26 if(TFC_Ticker[i]<0xFFFFFFFF)
redxeth 0:6432166d0781 27 {
redxeth 0:6432166d0781 28 TFC_Ticker[i]++;
redxeth 0:6432166d0781 29 }
redxeth 0:6432166d0781 30 }
redxeth 0:6432166d0781 31 }
redxeth 0:6432166d0781 32
codestar 2:729063e39fb3 33 //finds light intensity values of lines.
redxeth 0:6432166d0781 34
codestar 2:729063e39fb3 35 int FindBlack();
codestar 2:729063e39fb3 36
codestar 2:729063e39fb3 37 // finds and sets by reference the values of the left and right bounds
codestar 2:729063e39fb3 38 void Bounds(int &, int &, int);
anthonylamme 4:97014a4611c2 39
anthonylamme 4:97014a4611c2 40 // finds distance between bounds
anthonylamme 3:04f91137660a 41 int distance(int &, int &, int);
anthonylamme 4:97014a4611c2 42
anthonylamme 4:97014a4611c2 43 // returns interger for turn direction 0 for left 1 for right
anthonylamme 4:97014a4611c2 44
anthonylamme 4:97014a4611c2 45 int turnDir( int &, int &, int, int);
anthonylamme 4:97014a4611c2 46 int startstop(int);
anthonylamme 4:97014a4611c2 47
anthonylamme 4:97014a4611c2 48 //void turnLeft(int &, int &, int, int); needs to be finished
anthonylamme 4:97014a4611c2 49 //void turnRight(int &, int &, int, int); needs to be finished
redxeth 0:6432166d0781 50
redxeth 0:6432166d0781 51 int main()
redxeth 0:6432166d0781 52 {
codestar 1:4d7f3b5b7463 53 uint32_t i,t,time = 0;
codestar 1:4d7f3b5b7463 54
anthonylamme 4:97014a4611c2 55 int a = 200, b = 200, d = 200;
codestar 2:729063e39fb3 56
codestar 1:4d7f3b5b7463 57 int data[128];
codestar 1:4d7f3b5b7463 58
codestar 1:4d7f3b5b7463 59 int black = 0;
redxeth 0:6432166d0781 60
codestar 1:4d7f3b5b7463 61 PC.baud(9600);
redxeth 0:6432166d0781 62 TFC_TickerObj.attach_us(&TFC_TickerUpdate,2000);
redxeth 0:6432166d0781 63
redxeth 0:6432166d0781 64 TFC_Init();
redxeth 0:6432166d0781 65
anthonylamme 4:97014a4611c2 66 bool didInit = false ; // flag for track calibration
codestar 1:4d7f3b5b7463 67
redxeth 0:6432166d0781 68 for(;;)
redxeth 0:6432166d0781 69 {
redxeth 0:6432166d0781 70 //TFC_Task must be called in your main loop. This keeps certain processing happy (I.E. Serial port queue check)
redxeth 0:6432166d0781 71 // TFC_Task();
redxeth 0:6432166d0781 72
redxeth 0:6432166d0781 73 //This Demo program will look at the middle 2 switch to select one of 4 demo modes.
redxeth 0:6432166d0781 74 //Let's look at the middle 2 switches
redxeth 0:6432166d0781 75 switch((TFC_GetDIP_Switch()>>1)&0x03)
redxeth 0:6432166d0781 76 {
redxeth 0:6432166d0781 77 default:
anthonylamme 3:04f91137660a 78 case 0 ://initilazation case
anthonylamme 3:04f91137660a 79 if(TFC_Ticker[0]>50 && TFC_LineScanImageReady>0)
anthonylamme 3:04f91137660a 80 {
anthonylamme 3:04f91137660a 81 TFC_Ticker[0] = 0;
anthonylamme 3:04f91137660a 82 TFC_LineScanImageReady=0;
anthonylamme 4:97014a4611c2 83 if(TFC_PUSH_BUTTON_0_PRESSED&& didInit == false)
anthonylamme 3:04f91137660a 84 {
anthonylamme 3:04f91137660a 85 black = FindBlack();
anthonylamme 3:04f91137660a 86 d=distance(a,b,black);
anthonylamme 4:97014a4611c2 87
anthonylamme 4:97014a4611c2 88 PC.printf("%d \n" , a );
anthonylamme 4:97014a4611c2 89 PC.printf("%d \n", b );
anthonylamme 4:97014a4611c2 90 PC.printf("%d \n", black);
anthonylamme 4:97014a4611c2 91 PC.printf("%d \n" , d );
anthonylamme 4:97014a4611c2 92
anthonylamme 4:97014a4611c2 93 didInit = true; // sets initialzation to true
anthonylamme 3:04f91137660a 94 }
anthonylamme 3:04f91137660a 95 }
anthonylamme 3:04f91137660a 96 TFC_SetServo(0,0.0);
anthonylamme 4:97014a4611c2 97
anthonylamme 4:97014a4611c2 98 // this is test code to have the car print if a turn case happened.
anthonylamme 4:97014a4611c2 99
anthonylamme 4:97014a4611c2 100 if(didInit) // check to see if initalized
anthonylamme 4:97014a4611c2 101 {
anthonylamme 4:97014a4611c2 102 if(d < distance(a,b,black))
anthonylamme 4:97014a4611c2 103 {
anthonylamme 4:97014a4611c2 104 int whichTurn = 2; // impossible for function to return
anthonylamme 4:97014a4611c2 105
anthonylamme 4:97014a4611c2 106 whichTurn = turnDir(a,b,black,d); // sets which turn to 0 for left and 1 for right
anthonylamme 4:97014a4611c2 107
anthonylamme 4:97014a4611c2 108 PC.printf("%d \n", whichTurn);
anthonylamme 4:97014a4611c2 109 }
anthonylamme 4:97014a4611c2 110 }
anthonylamme 3:04f91137660a 111 break;
redxeth 0:6432166d0781 112
anthonylamme 4:97014a4611c2 113 case 1: // moves servo and prints pot value.
redxeth 0:6432166d0781 114
anthonylamme 4:97014a4611c2 115
redxeth 0:6432166d0781 116 if(TFC_Ticker[0]>=20)
redxeth 0:6432166d0781 117 {
redxeth 0:6432166d0781 118 TFC_Ticker[0] = 0; //reset the Ticker
redxeth 0:6432166d0781 119 //Every 20 mSeconds, update the Servos
redxeth 0:6432166d0781 120 TFC_SetServo(0,TFC_ReadPot(0));
redxeth 0:6432166d0781 121 TFC_SetServo(1,TFC_ReadPot(1));
codestar 1:4d7f3b5b7463 122
codestar 1:4d7f3b5b7463 123
redxeth 0:6432166d0781 124 }
codestar 1:4d7f3b5b7463 125
codestar 1:4d7f3b5b7463 126 if(TFC_PUSH_BUTTON_1_PRESSED)
codestar 1:4d7f3b5b7463 127 {
codestar 1:4d7f3b5b7463 128
anthonylamme 4:97014a4611c2 129 PC.printf("%f", TFC_ReadPot(0));
codestar 1:4d7f3b5b7463 130 }
codestar 1:4d7f3b5b7463 131
codestar 1:4d7f3b5b7463 132
redxeth 0:6432166d0781 133 //Let's put a pattern on the LEDs
redxeth 0:6432166d0781 134 if(TFC_Ticker[1] >= 125)
redxeth 0:6432166d0781 135 {
redxeth 0:6432166d0781 136 TFC_Ticker[1] = 0;
redxeth 0:6432166d0781 137 t++;
redxeth 0:6432166d0781 138 if(t>4)
redxeth 0:6432166d0781 139 {
redxeth 0:6432166d0781 140 t=0;
redxeth 0:6432166d0781 141 }
redxeth 0:6432166d0781 142 TFC_SetBatteryLED_Level(t);
redxeth 0:6432166d0781 143 }
redxeth 0:6432166d0781 144
codestar 1:4d7f3b5b7463 145 // TFC_SetMotorPWM(0,0); //Make sure motors are off
codestar 1:4d7f3b5b7463 146 // TFC_HBRIDGE_DISABLE;
redxeth 0:6432166d0781 147
redxeth 0:6432166d0781 148
redxeth 0:6432166d0781 149 break;
redxeth 0:6432166d0781 150
anthonylamme 4:97014a4611c2 151 case 2 ://case 2 will run program after case 0
anthonylamme 4:97014a4611c2 152 TFC_HBRIDGE_ENABLE;
anthonylamme 4:97014a4611c2 153 if(TFC_PUSH_BUTTON_0_PRESSED)
anthonylamme 4:97014a4611c2 154 {
anthonylamme 4:97014a4611c2 155 while(true)
codestar 1:4d7f3b5b7463 156 {
anthonylamme 4:97014a4611c2 157 dark=FindBlack();//determines if its dark
anthonylamme 4:97014a4611c2 158 while(d==distance(a,b,black))//if straight line it just goes forward
anthonylamme 4:97014a4611c2 159 {
anthonylamme 4:97014a4611c2 160 TFC_SetMotorPWM(.6,.6);
anthonylamme 4:97014a4611c2 161 }
anthonylamme 4:97014a4611c2 162 if(turnDir(a,b,black,d)==1)//straight line is broken determine direction if 1 go right
anthonylamme 4:97014a4611c2 163 {
anthonylamme 4:97014a4611c2 164 turnRight();
anthonylamme 4:97014a4611c2 165 }
anthonylamme 4:97014a4611c2 166 if(turnDir(a,b,black,d)==0)//straight line is broken determine direction if 0 go right
anthonylamme 4:97014a4611c2 167 {
anthonylamme 4:97014a4611c2 168 turnLeft();
anthonylamme 4:97014a4611c2 169 }
anthonylamme 4:97014a4611c2 170 if(FindBlack()==2000)//if white line then find black will return starting value because no black line
anthonylamme 4:97014a4611c2 171 {
anthonylamme 4:97014a4611c2 172 TFC_SetMotorPWM(.6,.6);//go straight for given time
anthonylamme 4:97014a4611c2 173 wait(0.146);
anthonylamme 4:97014a4611c2 174 continue;// start loop over and see where you are
anthonylamme 4:97014a4611c2 175 }
anthonylamme 4:97014a4611c2 176 if(dark>black)//determine if hill then slow down until hill is over
anthonylamme 4:97014a4611c2 177 {
anthonylamme 4:97014a4611c2 178 TFC_SetMotorPWM(0,0);
anthonylamme 4:97014a4611c2 179 wait(0.146);
anthonylamme 4:97014a4611c2 180 continue;
anthonylamme 4:97014a4611c2 181 }
anthonylamme 4:97014a4611c2 182 if(dark<black)//determine if dark then go foreword
anthonylamme 4:97014a4611c2 183 {
anthonylamme 4:97014a4611c2 184 TFC_SetMotorPWM(.6,.6);
anthonylamme 4:97014a4611c2 185 wait(0.143);
anthonylamme 4:97014a4611c2 186 continue;
anthonylamme 4:97014a4611c2 187 }
anthonylamme 4:97014a4611c2 188 if(startstop==1)// if start line is seen stop
anthonylamme 4:97014a4611c2 189 {
anthonylamme 4:97014a4611c2 190 TFC_SetMotorPWM(0,0);
anthonylamme 4:97014a4611c2 191 TFC_HBRIDGE_DISABLE;
anthonylamme 4:97014a4611c2 192 break;
anthonylamme 4:97014a4611c2 193 }
anthonylamme 4:97014a4611c2 194 }
anthonylamme 4:97014a4611c2 195 }
redxeth 0:6432166d0781 196 break;
redxeth 0:6432166d0781 197
redxeth 0:6432166d0781 198 case 3 :
redxeth 0:6432166d0781 199
redxeth 0:6432166d0781 200
redxeth 0:6432166d0781 201 //Demo Mode 3 will be in Freescale Garage Mode. It will beam data from the Camera to the
redxeth 0:6432166d0781 202 //Labview Application
redxeth 0:6432166d0781 203
redxeth 0:6432166d0781 204
redxeth 0:6432166d0781 205 if(TFC_Ticker[0]>50 && TFC_LineScanImageReady>0)
redxeth 0:6432166d0781 206 {
redxeth 0:6432166d0781 207 TFC_Ticker[0] = 0;
redxeth 0:6432166d0781 208 TFC_LineScanImageReady=0;
anthonylamme 4:97014a4611c2 209 // PC.printf("\r\n");
anthonylamme 4:97014a4611c2 210 // PC.printf("L:");
redxeth 0:6432166d0781 211
redxeth 0:6432166d0781 212 if(t==0)
redxeth 0:6432166d0781 213 t=4;
redxeth 0:6432166d0781 214 else
redxeth 0:6432166d0781 215 t--;
redxeth 0:6432166d0781 216
redxeth 0:6432166d0781 217 TFC_SetBatteryLED_Level(t);
redxeth 0:6432166d0781 218
redxeth 0:6432166d0781 219 // camera 1
codestar 1:4d7f3b5b7463 220
codestar 1:4d7f3b5b7463 221 if(TFC_PUSH_BUTTON_0_PRESSED)
codestar 1:4d7f3b5b7463 222 {
codestar 1:4d7f3b5b7463 223 //Demo Mode 3 will be in Freescale Garage Mode. It will beam data from the Camera to the
codestar 1:4d7f3b5b7463 224 //Labview Application
codestar 1:4d7f3b5b7463 225
codestar 1:4d7f3b5b7463 226
codestar 1:4d7f3b5b7463 227 // camera 1
redxeth 0:6432166d0781 228 for(i=0;i<128;i++)
redxeth 0:6432166d0781 229 {
codestar 1:4d7f3b5b7463 230 if(TFC_LineScanImage0[i]<=black)
codestar 1:4d7f3b5b7463 231 {
codestar 2:729063e39fb3 232 // zero is black
codestar 2:729063e39fb3 233
codestar 1:4d7f3b5b7463 234 data[i]=0;
codestar 1:4d7f3b5b7463 235 }
codestar 1:4d7f3b5b7463 236 else
codestar 1:4d7f3b5b7463 237 {
codestar 2:729063e39fb3 238 // one is white
codestar 1:4d7f3b5b7463 239 data[i]=1;
codestar 1:4d7f3b5b7463 240 }
anthonylamme 4:97014a4611c2 241 PC.printf("%d", data[i]);
redxeth 0:6432166d0781 242 }
anthonylamme 4:97014a4611c2 243 PC.printf("\r");
codestar 1:4d7f3b5b7463 244 }
redxeth 0:6432166d0781 245 }
redxeth 0:6432166d0781 246
redxeth 0:6432166d0781 247 break;
redxeth 0:6432166d0781 248 }
redxeth 0:6432166d0781 249 }
redxeth 0:6432166d0781 250
redxeth 0:6432166d0781 251
redxeth 0:6432166d0781 252 }
anthonylamme 4:97014a4611c2 253
codestar 2:729063e39fb3 254
codestar 2:729063e39fb3 255 // finds and sets by reference the values of the left and right bounds
codestar 2:729063e39fb3 256
codestar 2:729063e39fb3 257 void bounds(int &a,int &b,int black)
codestar 2:729063e39fb3 258 {
codestar 2:729063e39fb3 259 for(int i=0; i<128; i++)
codestar 2:729063e39fb3 260 {
anthonylamme 4:97014a4611c2 261 if(i==0)
codestar 2:729063e39fb3 262 {
codestar 2:729063e39fb3 263 a = i;
codestar 2:729063e39fb3 264 }
codestar 2:729063e39fb3 265
anthonylamme 4:97014a4611c2 266 else if(TFC_LineScanImage0[i] <= black)
codestar 2:729063e39fb3 267 {
codestar 2:729063e39fb3 268 //if there are to black values next to eachother it sets a to newer inside value.
anthonylamme 4:97014a4611c2 269 if ( a == 0 && i!=0)
anthonylamme 4:97014a4611c2 270 a = i;
anthonylamme 4:97014a4611c2 271
anthonylamme 4:97014a4611c2 272 else if( (i-a) == 1 )
codestar 2:729063e39fb3 273 {
codestar 2:729063e39fb3 274 a = i;
codestar 2:729063e39fb3 275 }
codestar 2:729063e39fb3 276
codestar 2:729063e39fb3 277 // if there is a space between black values the next black value is the right bound.
codestar 2:729063e39fb3 278 else
codestar 2:729063e39fb3 279 {
codestar 2:729063e39fb3 280 // sets the right inside bound and ends the loop.
anthonylamme 4:97014a4611c2 281
codestar 2:729063e39fb3 282 b = i;
codestar 2:729063e39fb3 283 break;
codestar 2:729063e39fb3 284 }
codestar 2:729063e39fb3 285 }
codestar 2:729063e39fb3 286 }
codestar 2:729063e39fb3 287 }
codestar 2:729063e39fb3 288 int FindBlack()
codestar 2:729063e39fb3 289 {
codestar 2:729063e39fb3 290 int low1=2000,low2=2000;
codestar 2:729063e39fb3 291 for(int i=2;i<64;i++)//first half of line scan
codestar 2:729063e39fb3 292 {
codestar 2:729063e39fb3 293 int ave=(TFC_LineScanImage0[i-2]+TFC_LineScanImage0[i-1]+TFC_LineScanImage0[i])/3;
codestar 2:729063e39fb3 294 if(i==2)
codestar 2:729063e39fb3 295 {
codestar 2:729063e39fb3 296 low1=ave;//first loop sets lowest average
codestar 2:729063e39fb3 297 }
codestar 2:729063e39fb3 298 if(low1>ave)
codestar 2:729063e39fb3 299 {
codestar 2:729063e39fb3 300 low1=ave;
codestar 2:729063e39fb3 301 }
codestar 2:729063e39fb3 302 }
codestar 2:729063e39fb3 303 for(int i=66;i<128;i++)//second half of line scan
codestar 2:729063e39fb3 304 {
codestar 2:729063e39fb3 305 int ave2=(TFC_LineScanImage0[i-2]+TFC_LineScanImage0[i-1]+TFC_LineScanImage0[i])/3;
codestar 2:729063e39fb3 306 if(i==66)
codestar 2:729063e39fb3 307 {
codestar 2:729063e39fb3 308 low2=ave2;
codestar 2:729063e39fb3 309 }
codestar 2:729063e39fb3 310 if(low2>ave2)
codestar 2:729063e39fb3 311 {
codestar 2:729063e39fb3 312 low2=ave2;
codestar 2:729063e39fb3 313 }
codestar 2:729063e39fb3 314 if(low1==low2)
codestar 2:729063e39fb3 315 {
codestar 2:729063e39fb3 316 return low1; //confirms bothe lines and breaks loop returns black
codestar 2:729063e39fb3 317 }
codestar 2:729063e39fb3 318 }
codestar 2:729063e39fb3 319 if(low1>low2)
codestar 2:729063e39fb3 320 {
codestar 2:729063e39fb3 321 return low1;
codestar 2:729063e39fb3 322 }
codestar 2:729063e39fb3 323 else
codestar 2:729063e39fb3 324 {
codestar 2:729063e39fb3 325 return low2;
codestar 2:729063e39fb3 326 }
anthonylamme 3:04f91137660a 327 }
anthonylamme 3:04f91137660a 328 int distance(int &a, int &b, int black)
anthonylamme 3:04f91137660a 329 {
anthonylamme 3:04f91137660a 330 bounds(a,b,black);
anthonylamme 4:97014a4611c2 331 return (b-a);
anthonylamme 3:04f91137660a 332 }
anthonylamme 4:97014a4611c2 333
anthonylamme 4:97014a4611c2 334 int turnDir( int &a, int &b, int black, int d)
anthonylamme 4:97014a4611c2 335 {
anthonylamme 4:97014a4611c2 336 int l = 200, r = 200;
anthonylamme 4:97014a4611c2 337
anthonylamme 4:97014a4611c2 338 bounds(a,b,black); // resets bounds for start of program
anthonylamme 4:97014a4611c2 339
anthonylamme 4:97014a4611c2 340 while(d != distance(l,r,black)) // keeps checking rate of change while approaching turn
anthonylamme 4:97014a4611c2 341 {
anthonylamme 4:97014a4611c2 342 if( abs(a-l) > abs(b-r) ) // if the change in the left direction is greater than the right
anthonylamme 4:97014a4611c2 343 {
anthonylamme 4:97014a4611c2 344 return 0; // this returns left
anthonylamme 4:97014a4611c2 345 }
anthonylamme 4:97014a4611c2 346
anthonylamme 4:97014a4611c2 347 if( abs(a-l) < abs(b-r)) // if the change in the right direction is greater than the left
anthonylamme 4:97014a4611c2 348 {
anthonylamme 4:97014a4611c2 349 return 1; // this returns right
anthonylamme 4:97014a4611c2 350 }
anthonylamme 4:97014a4611c2 351
anthonylamme 4:97014a4611c2 352 }
anthonylamme 4:97014a4611c2 353 }
anthonylamme 4:97014a4611c2 354
anthonylamme 4:97014a4611c2 355 /*void turnLeft(int &a, int &b,int black,int d)
anthonylamme 4:97014a4611c2 356 {
anthonylamme 4:97014a4611c2 357 // waits for the amount of time it takes to reach the turn
anthonylamme 4:97014a4611c2 358 wait(.146);
anthonylamme 4:97014a4611c2 359
anthonylamme 4:97014a4611c2 360
anthonylamme 4:97014a4611c2 361 // turns the wheels to the angle they need to be
anthonylamme 4:97014a4611c2 362 // while the distance between the lines
anthonylamme 4:97014a4611c2 363 // indicate the car is in a turn
anthonylamme 4:97014a4611c2 364
anthonylamme 4:97014a4611c2 365 while(d > distance(a, b, black) )
anthonylamme 4:97014a4611c2 366 {
anthonylamme 4:97014a4611c2 367 setservo(-.214652);
anthonylamme 4:97014a4611c2 368 }
anthonylamme 4:97014a4611c2 369
anthonylamme 4:97014a4611c2 370 // returns the wheels back to straight
anthonylamme 4:97014a4611c2 371
anthonylamme 4:97014a4611c2 372 setservo(0,0.0);
anthonylamme 4:97014a4611c2 373 }
anthonylamme 4:97014a4611c2 374
anthonylamme 4:97014a4611c2 375 */
anthonylamme 4:97014a4611c2 376 /* void turnRight(int &a, int &b,int black,int d)
anthonylamme 4:97014a4611c2 377 {
anthonylamme 4:97014a4611c2 378 // waits for the amount of time it takes to reach the turn
anthonylamme 4:97014a4611c2 379 wait(.146);
anthonylamme 4:97014a4611c2 380 while(d > distance(a, b, black) )
anthonylamme 4:97014a4611c2 381 {
anthonylamme 4:97014a4611c2 382 setservo(.2688640);
anthonylamme 4:97014a4611c2 383 }*/
anthonylamme 4:97014a4611c2 384 int startstop(int black)
anthonylamme 4:97014a4611c2 385 {
anthonylamme 4:97014a4611c2 386 int counter=0;
anthonylamme 4:97014a4611c2 387
anthonylamme 4:97014a4611c2 388 for(i=0;i<128;i++)
anthonylamme 4:97014a4611c2 389 {
anthonylamme 4:97014a4611c2 390 if(TFC_LineScanImage0[i]<=black)
anthonylamme 4:97014a4611c2 391 {
anthonylamme 4:97014a4611c2 392 // zero is black
anthonylamme 4:97014a4611c2 393 data[i]=0;
anthonylamme 4:97014a4611c2 394 counter++;
anthonylamme 4:97014a4611c2 395 }
anthonylamme 4:97014a4611c2 396 else
anthonylamme 4:97014a4611c2 397 {
anthonylamme 4:97014a4611c2 398 // one is white
anthonylamme 4:97014a4611c2 399 data[i]=1;
anthonylamme 4:97014a4611c2 400 }
anthonylamme 4:97014a4611c2 401 }
anthonylamme 4:97014a4611c2 402 if counter>6
anthonylamme 4:97014a4611c2 403 {
anthonylamme 4:97014a4611c2 404 return 1;
anthonylamme 4:97014a4611c2 405 }
anthonylamme 4:97014a4611c2 406 else
anthonylamme 4:97014a4611c2 407 {
anthonylamme 4:97014a4611c2 408 return 0;
anthonylamme 4:97014a4611c2 409 }
anthonylamme 4:97014a4611c2 410 }
anthonylamme 4:97014a4611c2 411
anthonylamme 4:97014a4611c2 412