Brian Daniels / rgb_sensor

Dependents:   rgb_sensor_buffer

Fork of rgb_sensor by Milosch Meriac

Files at this revision

API Documentation at this revision

Comitter:
meriac
Date:
Thu Jul 03 16:52:12 2014 +0000
Parent:
7:0d35392230be
Child:
9:7bd80f4a965e
Commit message:
Positive ADC reading, adjusted speed to 732/s

Changed in this revision

rgb_sensor.cpp Show annotated file Show diff for this revision Revisions of this file
rgb_sensor.h Show annotated file Show diff for this revision Revisions of this file
--- a/rgb_sensor.cpp	Thu Jul 03 09:30:13 2014 +0000
+++ b/rgb_sensor.cpp	Thu Jul 03 16:52:12 2014 +0000
@@ -229,12 +229,16 @@
 
 void RGB_Sensor::convert(TRGB &rgb)
 {
+    int i, sample;
+
     /* correct "DC" offset by subdstracting
      * environment light
      */
-    rgb.ch.red   = m_adc_aggregation[1] - m_adc_aggregation[0];   
-    rgb.ch.green = m_adc_aggregation[2] - m_adc_aggregation[0];   
-    rgb.ch.blue  = m_adc_aggregation[3] - m_adc_aggregation[0];
+    for(i=0; i<3; i++)
+    {
+        sample = m_adc_aggregation[0] - m_adc_aggregation[i+1];
+        rgb.data[i] = (sample<0) ? 0 : sample;
+    }
 } 
 
 bool RGB_Sensor::capture(TRGB &rgb)
--- a/rgb_sensor.h	Thu Jul 03 09:30:13 2014 +0000
+++ b/rgb_sensor.h	Thu Jul 03 16:52:12 2014 +0000
@@ -19,7 +19,7 @@
  * limitations under the License.
  */
  
- #ifndef __RGB_SENSOR_H__
+#ifndef __RGB_SENSOR_H__
 #define __RGB_SENSOR_H__
 
 #ifndef RGB_LED_ON
@@ -27,11 +27,11 @@
 #endif/*RGB_LED_ON*/
 
 #ifndef RGB_OVERSAMPLING
-#define RGB_OVERSAMPLING 128
+#define RGB_OVERSAMPLING 32
 #endif/*RGB_OVERSAMPLING*/
 
 #ifndef RGB_MAX_ADC_CLK
-#define RGB_MAX_ADC_CLK 1000000UL
+#define RGB_MAX_ADC_CLK 6000000UL
 #endif/*RGB_MAX_ADC_CLK*/
 
 #define RGB_CHANNELS 4