Don't want to screw something by updating the code as Ivelin updated himself while I was writing so I am forking it.

Dependencies:   LocalPositionSystem MMA8451Q Motor_Driver Sensors mbed

Fork of TDP_main by Yelfie

Revision:
16:3649eb1a056d
Parent:
15:6453cd351452
Child:
17:de8b3111ddc5
--- a/sensor_measure.h	Thu Mar 12 18:44:57 2015 +0000
+++ b/sensor_measure.h	Fri Mar 13 18:19:01 2015 +0000
@@ -17,14 +17,14 @@
 #define _SENSOR_MEASURE_H
 
 #define NUMBER_SAMPLES 20 // NUMBER OF SAMPLES FOR SENSOR TESTING
-#define NUMBER_SENSORS_REGULAR 8 // number for the array of sensors
+#define NUMBER_SENSORS_REGULAR 4 // number for the array of sensors
 #define NUMBER_SENSORS_SQUARE 0
 
 //define pinout for all the sensors
-DigitalIn pin_right_right_up(PTD0);
-DigitalIn pin_right_left_up(PTD2);
-DigitalIn pin_right_right_down(PTD2);
-DigitalIn pin_right_left_down(PTD3);
+DigitalIn pin_right_right_up(PTE5);
+DigitalIn pin_right_left_up(PTE2);
+DigitalIn pin_right_right_down(PTE3);
+DigitalIn pin_right_left_down(PTE4);
 DigitalIn pin_left_right_down(PTD4);
 DigitalIn pin_left_left_down(PTD5);
 //DigitalIn pin_left_right_up();
@@ -75,13 +75,17 @@
     right_left_up.grayValue = 0;
     right_left_up.state = 0;
     sensorArray [arrayBuilder++] = &right_left_up;
+    right_right_down.pin = &pin_right_right_down;
+    sensorArray [arrayBuilder++] = &right_right_down;
+    right_left_down.pin = &pin_right_left_down;
+    sensorArray[arrayBuilder++] = &right_left_down;
     //and contiune so on..
 }
 
-
+int counter1 = 0;
 //measuring function - returning whether it is black or white line 
 //"0" - black, "1" - white
-int measure (sensor_data sensor){
+int measure (sensor_data *sensor){
     
     sensorTimer.reset(); //reset the timer
     double freq,period = 0.0;
@@ -90,7 +94,7 @@
     int sensor_new  = 0;
     //double time_1 = sensorTimer.read();  used for debugging
     while (n < NUMBER_SAMPLES){
-        sensor_new = sensor.pin->read();
+        sensor_new = sensor->pin->read();
         if ( sensor_new== 1 && sensor_old == 0){ // detect on rising edge 
             n++;
         }
@@ -101,21 +105,23 @@
    
     period = time_2/((double)NUMBER_SAMPLES); // Get time
     freq = (1/period);   // Convert period (in us) to frequency (Hz). 
-    // pc.printf(" period is  %f  and freq is  %f ", period,freq); // Used for debugging
+    //pc.printf(" period is  %f  and freq is  %f ", period,freq); // Used for debugging
+    
+    sensor->state = freq;
     
-    if (sensor.grayValue != 0 && freq < (sensor.grayValue +  1000) && freq > (sensor.grayValue - 1000)) { //definitely not sure about that!
-        //this is a gray value sensor in its gray region
-        sensor.state = 2;
-        return 2;
-    }
-    else if (freq < sensor.blackValue*2){
-        sensor.state = 0;    //if it's less than black value it is black
-        return 0;
-    }
-    else {
-        sensor.state = 1;
-    }    
+//    if (sensor->grayValue != 0 && freq < (sensor->grayValue +  1000) && freq > (sensor.grayValue - 1000)) { //definitely not sure about that!
+//        //this is a gray value sensor in its gray region
+//        sensor->state = 2;
+//        return 2;
+//    }
+//    else if (freq < sensor->blackValue*2){
+//        sensor->state = 0;    //if it's less than black value it is black
+//        return 0;
+//    }
+//    else {
+//        sensor->state = 1;
+//    }    
         return 1;
-   //(freq < sensor.black_value*2)? 1 : 0; //freq
+   //(freq < sensor->black_value*2)? 1 : 0; //freq
 }
 #endif
\ No newline at end of file