Median filtered & triggered + buffered RGB readings

Dependencies:   mbed rgb_sensor_buffer

Files at this revision

API Documentation at this revision

Comitter:
meriac
Date:
Thu Jul 03 17:55:01 2014 +0000
Parent:
2:f72e7a4d7395
Child:
4:a4538586c75e
Commit message:
Fixed Eigenvector calculation

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Jul 03 17:47:31 2014 +0000
+++ b/main.cpp	Thu Jul 03 17:55:01 2014 +0000
@@ -72,6 +72,7 @@
 
 int main() {
     int res, i;
+    double magnitude;
     TRGB color;
 
     console.baud(115200);
@@ -102,12 +103,12 @@
         /* calculate RGB median */
         median(color, res);
         /* print normalized median */
-        i = (color.ch.red + color.ch.green + color.ch.blue);
+        magnitude = sqrt((((double)color.ch.red*color.ch.red)+((double)color.ch.green*color.ch.green)+((double)color.ch.blue*color.ch.blue)));
         console.printf("\t[%1.4f,%1.4f,%1.4f,%5i], // %i values in %ims (%i/s)\n\r",
-            ((double)color.ch.red)/i,
-            ((double)color.ch.green)/i,
-            ((double)color.ch.blue)/i,
-            (int)((sqrt((((double)color.ch.red*color.ch.red)+((double)color.ch.green*color.ch.green)+((double)color.ch.blue*color.ch.blue)))/RGB_OVERSAMPLING)+0.5),
+            color.ch.red   / magnitude,
+            color.ch.green / magnitude,
+            color.ch.blue  / magnitude,
+            (int)((magnitude / RGB_OVERSAMPLING)+0.5),
             res,
             timer.read_ms(),
             (res*1000UL)/timer.read_ms()