Colour sensors calibrated

Dependencies:   mbed-rtos mbed Servo QEI

Fork of ICRSEurobot13 by Thomas Branch

Revision:
4:1be0f6c6ceae
Child:
7:4340355261f9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/Colour/Colour.cpp	Wed Apr 03 17:54:53 2013 +0000
@@ -0,0 +1,30 @@
+
+// Eurobot13 Colour.cpp
+
+#include "Colour.h"
+
+void Colour::ReadLed (Led &led, float &avg, float &stdev, const int measureNum){
+    LedsOff();
+    led.on();
+    double x = 0, x2 = 0;
+    for (int i = measureNum; i != 0; i--) {
+        float v = pt.read();
+        x += v;
+        x2+= v*v;
+    }
+    avg = x / measureNum;
+    stdev = sqrt(x2 / measureNum - avg*avg);
+    LedsOff();
+    //pc.printf("Phototransistor Analog is: %f\t%f\n\r", avg, stdev);
+}
+
+bool Colour::isColour(Led &led, const float &avg, const float &stdev, const float numstddev){
+    float avg2, stdev2;
+    ReadLed(led, avg2, stdev2);
+
+    if (avg + numstddev*stdev < avg2 - numstddev*stdev2) {
+        return true;
+    } else {
+        return false;
+    }
+}
\ No newline at end of file