fatboyslim / Mbed 2 deprecated buttontest

Dependencies:   FRDM-TFC mbed

Revision:
11:d65d6d7fc85e
Parent:
10:6d9d70a240fd
Child:
12:288df1e95dec
--- a/main.cpp	Mon Feb 23 20:21:15 2015 +0000
+++ b/main.cpp	Mon Feb 23 20:49:46 2015 +0000
@@ -16,6 +16,12 @@
     bool linescan_ping_pong = false;
     bool linescan_enable = true;
     
+    int black_values_list[128];
+    int black_value_count = 0;
+    int black_center_value = 0;
+    int sum_black = 0;
+    
+    
     //uint16_t  MyImage0Buffer[2][128];
     //uint16_t  MyImage1Buffer[2][128];
     
@@ -92,7 +98,7 @@
             {
              if (TFC_LineScanImageReady !=0)
                 {
-                // this block sucks
+                
                 if (linescan_ping_pong) //checking channel 0
                     {
                         //...
@@ -108,25 +114,56 @@
                             shitnum = 1;
                         
                         TFC_SetBatteryLED(shitnum);
+                        
+                        // checking for center line?
+                        for (uint16_t i=0; i<128; i++)
+                            {
+                                if ((*(TFC_LineScanImage0+i) > 450)) 
+                                {
+                                    black_values_list[black_value_count] = i;
+                                    black_value_count++;
+                                }
+                            }
+                        
+                        for(int i=0; i<black_value_count; i++)
+                            {
+                                sum_black += black_values_list[i];
+                            }
+                        
+                        black_center_value= sum_black / black_value_count;
+                        
+                        if (black_center_value > 64)
+                            {
+                                current_servo_position = current_servo_position-.005;
+                                if(current_servo_position <= -0.4)
+                                    current_servo_position = -0.4;
+                                TFC_SetServo(0, current_servo_position);
+                            }
+                        
+                        if (black_center_value < 64)
+                            {
+                                current_servo_position = current_servo_position+.005;
+                                if(current_servo_position <= +0.4)
+                                    current_servo_position = +0.4;
+                                TFC_SetServo(0, current_servo_position);
+                            }
+                        
+                        black_value_count = 0;
+                        black_center_value = 0;
+                        sum_black = 0;
+                        
+                        // end checking for center line
+                        
+                        
                         linescan_ping_pong = false;
-                    }
+                    } // end checking channel 0
                 else                    //checking channel 1
                     {
                         //...
                         //TFC_SetBatteryLED(*TFC_LineScanImage1+4);
                         linescan_ping_pong = true;
                     }
-                // end of this block sucks
-                    
-                /*    this block sucks too
-                if ((* TFC_LineScanImage0) > (* TFC_LineScanImage1))
-                    TFC_SetBatteryLED(*TFC_LineScanImage0);
-                else
-                    TFC_SetBatteryLED(*TFC_LineScanImage1);
-                */    
-                    
-                //TFC_SetBatteryLED(*TFC_LineScanImage0+4);    
-                    
+                
                     
                 TFC_LineScanImageReady ==0;  // since we used it, we reset the flag
                 }// end imageready