added distance function, added turnDir function, started function that completes left turn

Dependencies:   FRDM-TFC

Fork of TFC-TEST_TXSTATE_TEAM6v2 by Anthony Lamme

Revision:
1:4d7f3b5b7463
Parent:
0:6432166d0781
Child:
2:729063e39fb3
--- a/main.cpp	Tue Apr 15 02:38:04 2014 +0000
+++ b/main.cpp	Sat Apr 04 19:41:57 2015 +0000
@@ -34,13 +34,19 @@
  
 int main()
 {
-    uint32_t i,t = 0;
+    uint32_t i,t,time = 0;
+    
+    int data[128];
+    
+    int black = 0;
   
-    PC.baud(115200);
+    PC.baud(9600);
     TFC_TickerObj.attach_us(&TFC_TickerUpdate,2000);
    
     TFC_Init();
     
+    bool timeTrue = true;
+    
     for(;;)
     {      
         //TFC_Task must be called in your main loop.  This keeps certain processing happy (I.E. Serial port queue check)
@@ -52,29 +58,10 @@
             {
             default:
             case 0 :
-                //Demo mode 0 just tests the switches and LED's
-                if(TFC_PUSH_BUTTON_0_PRESSED)
-                    TFC_BAT_LED0_ON;
-                else
-                    TFC_BAT_LED0_OFF;
-                
-                if(TFC_PUSH_BUTTON_1_PRESSED)
-                    TFC_BAT_LED3_ON;
-                else
-                    TFC_BAT_LED3_OFF;
-                
+            
+            TFC_HBRIDGE_ENABLE;
+                TFC_SetMotorPWM(.6,.6);
                 
-                if(TFC_GetDIP_Switch()&0x01)
-                    TFC_BAT_LED1_ON;
-                else
-                    TFC_BAT_LED1_OFF;
-                
-                if(TFC_GetDIP_Switch()&0x08)
-                    TFC_BAT_LED2_ON;
-                else
-                    TFC_BAT_LED2_OFF;
-                
-                break;
                     
             case 1:
                 
@@ -85,7 +72,17 @@
                     //Every 20 mSeconds, update the Servos
                     TFC_SetServo(0,TFC_ReadPot(0));
                     TFC_SetServo(1,TFC_ReadPot(1));
+                    
+                  
                 }
+                
+                 if(TFC_PUSH_BUTTON_1_PRESSED)
+                   { 
+                   
+                    TERMINAL_PRINTF("%f", TFC_ReadPot(0));
+                    }
+                
+                
                 //Let's put a pattern on the LEDs
                 if(TFC_Ticker[1] >= 125)
                 {
@@ -98,31 +95,60 @@
                     TFC_SetBatteryLED_Level(t);
                 }
                 
-                TFC_SetMotorPWM(0,0); //Make sure motors are off
-                TFC_HBRIDGE_DISABLE;
+              //  TFC_SetMotorPWM(0,0); //Make sure motors are off
+              //  TFC_HBRIDGE_DISABLE;
             
 
                 break;
                 
             case 2 :
+              
+         
+                //Demo Mode 3 will be in Freescale Garage Mode.  It will beam data from the Camera to the 
+                //Labview Application
                 
-                //Demo Mode 2 will use the Pots to make the motors move
-                TFC_HBRIDGE_ENABLE;
-               
-                TFC_SetMotorPWM(TFC_ReadPot(0),TFC_ReadPot(1));
                 
+                if(TFC_Ticker[0]>50 && TFC_LineScanImageReady>0)
+                    {
+                     TFC_Ticker[0] = 0;
+                     TFC_LineScanImageReady=0;
+                    // TERMINAL_PRINTF("\r\n");
+                    // TERMINAL_PRINTF("L:");
+                     
+                        if(t==0)
+                            t=4;
+                        else
+                            t--;
+                        
+                         TFC_SetBatteryLED_Level(t);
                         
-                //Let's put a pattern on the LEDs
-                if(TFC_Ticker[1] >= 125)
-                    {
-                        TFC_Ticker[1] = 0;
-                            t++;
-                            if(t>4)
-                            {
-                                t=0;
-                            }           
-                        TFC_SetBatteryLED_Level(t);
-                    }
+                         // camera 1
+                         
+                         if(TFC_PUSH_BUTTON_0_PRESSED)
+                    {          
+                               //Demo Mode 3 will be in Freescale Garage Mode.  It will beam data from the Camera to the 
+                //Labview Application
+                        int highest = 0;
+                        
+                         // camera 1
+                         for(i=0;i<128;i++)
+                         {
+                               if(i==0)
+                               {
+                                  highest = TFC_LineScanImage0[i];
+                                }
+                               if(TFC_LineScanImage0[i]>highest)
+                               {
+                                   highest = TFC_LineScanImage0[i];
+                               }    
+                         }
+                         
+                         black = highest;
+                         
+                         TERMINAL_PRINTF("%i", black);
+                
+                
+               
                 break;
             
             case 3 :
@@ -136,8 +162,8 @@
                     {
                      TFC_Ticker[0] = 0;
                      TFC_LineScanImageReady=0;
-                     TERMINAL_PRINTF("\r\n");
-                     TERMINAL_PRINTF("L:");
+                    // TERMINAL_PRINTF("\r\n");
+                    // TERMINAL_PRINTF("L:");
                      
                         if(t==0)
                             t=4;
@@ -147,20 +173,39 @@
                          TFC_SetBatteryLED_Level(t);
                         
                          // camera 1
+                         
+                         if(TFC_PUSH_BUTTON_0_PRESSED)
+                    {          
+                               //Demo Mode 3 will be in Freescale Garage Mode.  It will beam data from the Camera to the 
+                //Labview Application
+
+                        
+                         // camera 1
                          for(i=0;i<128;i++)
                          {
-                               TERMINAL_PRINTF("%X,",TFC_LineScanImage0[i]);
+                               if(TFC_LineScanImage0[i]<=black)
+                               {
+                                   data[i]=0;
+                                }
+                                else
+                                {
+                                    data[i]=1;
+                                }
+                                TERMINAL_PRINTF("%d", data[i]);
                          }
+                         TERMINAL_PRINTF("\r");
                         
                         // camera 2
-                         for(i=0;i<128;i++)
+                      /*   for(i=0;i<128;i++)
                          {
                                  if(i==127)
                                      TERMINAL_PRINTF("%X\r\n",TFC_LineScanImage1[i]);
                                  else
                                      TERMINAL_PRINTF("%X,",TFC_LineScanImage1[i]);
                            
-                         }
+                         } */
+                         
+                      }   
                     }
                  
                 break;
@@ -169,4 +214,5 @@
     
  
 }
- 
+}
+}
\ No newline at end of file