example for using the rgb_color_sensor class

Dependencies:   mbed rgb_sensor

Revision:
5:1b0f9427be32
Parent:
4:fbbc729f4152
Child:
6:236bee733ec3
--- a/main.cpp	Fri Jun 27 12:15:32 2014 +0000
+++ b/main.cpp	Sat Jun 28 07:08:00 2014 +0000
@@ -45,13 +45,13 @@
 
     console.printf("\t[");
     for(i=0; i<COUNT(color.data); i++)
-        console.printf("%s%04i", i?",":"", color.data[i] / RGB_OVERSAMPLING);
-    console.printf("]\n\r");
+        console.printf("%s%4i", i?",":"", color.data[i] / RGB_OVERSAMPLING);
+    console.printf("]");
 }
 
 int main() {
-    int i,j;
-    TRGB color, *p;
+    int i;
+    TRGB color;
 
     console.baud(115200);
 
@@ -61,6 +61,7 @@
     /* detect a single RGB value to demo synchronous API */
     rgb.capture(color);
     rgb_print(color);
+    console.printf(";\r\n");
 
     /* needed for time measurement */
     Timer timer;
@@ -81,16 +82,16 @@
         /* stop time measurement */
         timer.stop();
 
-        console.printf("// captured %i values in %i ms\n\rvar test = [\n\r", g_buffer_pos, timer.read_ms());
-        for(j=0; j<RGB_VALUES; j++)
+        console.printf("// captured %i values in %i ms (%i/s)\r\nvar test = [\r\n",
+            RGB_VALUES,
+            timer.read_ms(),
+            (RGB_VALUES*1000UL)/timer.read_ms());
+
+        for(i=0; i<RGB_VALUES; i++)
         {
-            p = &g_buffer[j];
-            for(i=0; i<COUNT(color.data); i++)
-                console.printf("%s%+04i", i?",":"\t[", p->data[i] / RGB_OVERSAMPLING);
-            if(j<(RGB_VALUES-1))
-                console.printf("],\n\r");
+            rgb_print(g_buffer[i]);
+            console.printf(i<(RGB_VALUES-1) ? ",\r\n":"];\r\n\r\n");
         }
-        console.printf("]];\n\r\n\r");
 
         /* visible intersection between captures */
         wait_ms(100);