Discrete RGB colour sensor using a colour LED flashing at high speed and a monochrome LDR (light dependent resistor) for detecting the colour via ADC conversion. The library implements interrupt driven ADC conversion at high speed (370 RGB readings per second, 128 times oversampling per channelfor noise reduction). The detection can optionally run in background.

Dependents:   rgb_sensor_buffer discrete_rgb_color_sensor_example

Revision:
3:50e1ac3c56db
Parent:
2:4545984e62b6
Child:
5:1fed2b68e661
--- a/rgb_sensor.h	Fri Jun 27 07:21:51 2014 +0000
+++ b/rgb_sensor.h	Fri Jun 27 11:36:15 2014 +0000
@@ -47,20 +47,23 @@
     int data[3];
 } TRGB;
 
+typedef bool (*TRGB_Callback)(const TRGB &rgb);
+
 class RGB_Sensor
 {
     public:
       RGB_Sensor(PinName red, PinName green, PinName blue, PinName adc);
       ~RGB_Sensor(void);
       bool capture(TRGB &rgb);
-      bool capture(void);
-      bool wait(TRGB &rgb);
+      bool capture(const TRGB_Callback callback);
+      bool wait(void);
     protected:
+      TRGB_Callback m_callback;
       bool m_done;
       uint8_t m_adc_channel, m_rgb_channel;
       DigitalOut m_red, m_green, m_blue;
       int m_adc_aggregation[RGB_CHANNELS], m_adc_count;
-      bool wait(void);
+      void convert(TRGB &rgb);
     private:
       static void __adc_irq(void);
       void adc_irq(void);