Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: rgb_sensor_buffer discrete_rgb_color_sensor_example
rgb_sensor.h
00001 /* Discrete RGB color sensor 00002 * 00003 * - uses single-channel light-dependent resistor (via ADC) 00004 * and a RGB LED. 00005 * - compensates background light 00006 * 00007 * Copyright (c) 2014 ARM Limited 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); 00010 * you may not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, 00017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #ifndef __RGB_SENSOR_H__ 00023 #define __RGB_SENSOR_H__ 00024 00025 #define RGB_MASK 0xFFF 00026 00027 #ifndef RGB_LED_ON 00028 #define RGB_LED_ON true 00029 #endif/*RGB_LED_ON*/ 00030 00031 #ifndef RGB_OVERSAMPLING 00032 #define RGB_OVERSAMPLING 32 00033 #endif/*RGB_OVERSAMPLING*/ 00034 00035 #ifndef RGB_SENSOR_IGNORE 00036 #define RGB_SENSOR_IGNORE (RGB_OVERSAMPLING/2) 00037 #endif/*RGB_SENSOR_IGNORE*/ 00038 00039 00040 #ifndef RGB_MAX_ADC_CLK 00041 #define RGB_MAX_ADC_CLK 6000000UL 00042 #endif/*RGB_MAX_ADC_CLK*/ 00043 00044 #define RGB_CHANNELS 4 00045 00046 typedef struct 00047 { 00048 int red,green,blue; 00049 } TRGB_Channel; 00050 00051 typedef union 00052 { 00053 TRGB_Channel ch; 00054 int data[3]; 00055 } TRGB; 00056 00057 typedef bool (*TRGB_Callback)(const TRGB &rgb); 00058 00059 class RGB_Sensor 00060 { 00061 public: 00062 RGB_Sensor(PinName red, PinName green, PinName blue, PinName adc); 00063 ~RGB_Sensor(void); 00064 bool capture(TRGB &rgb); 00065 bool capture(const TRGB_Callback callback); 00066 bool wait(void); 00067 protected: 00068 TRGB_Callback m_callback; 00069 bool m_done; 00070 uint8_t m_adc_channel, m_rgb_channel; 00071 DigitalOut m_red, m_green, m_blue; 00072 int m_adc_filter[RGB_CHANNELS][2], m_adc_filter_pos; 00073 int m_adc_aggregation[RGB_CHANNELS], m_adc_count; 00074 void convert(TRGB &rgb); 00075 int filter(int sample); 00076 private: 00077 static void __adc_irq(void); 00078 void adc_irq(void); 00079 static RGB_Sensor *m_global; 00080 }; 00081 00082 #endif/*__RGB_SENSOR_H__*/
Generated on Fri Jul 15 2022 11:42:08 by
1.7.2