![](/media/cache/profiles/093b60fd0557804c8ba0cbf1453da22f.jpg.50x50_q85.jpg)
example for using the rgb_color_sensor class
main.cpp
- Committer:
- meriac
- Date:
- 2014-06-25
- Revision:
- 0:d034f4b3b23c
- Child:
- 3:3649eaf4f954
File content as of revision 0:d034f4b3b23c:
/* Discrete RGB color sensor * * - uses single-channel light-dependent resistor (via ADC) * and a RGB LED. * - compensates background light * * Copyright (c) 2014 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <mbed.h> #include "rgb_sensor.h" #define COUNT(x) (sizeof(x)/sizeof(x[0])) int main() { TRGB color; int i, seq; /* serial console */ Serial console(USBTX, USBRX); console.baud(115200); /* R,G,B pins and ADC for light dependent resistor */ RGB_Sensor rgb(p23,p24,p25,p20); /* needed for time measurement */ Timer timer; seq = 0; while(1) { /* start four channel RGB conversion */ timer.reset(); timer.start(); /* detect RGB value */ rgb.capture(color); /* stop time measurement */ timer.stop(); console.printf("%06i", seq++); for(i=0; i<COUNT(color.data); i++) console.printf(",%04i", color.data[i] / RGB_OVERSAMPLING); console.printf(",%i\n\r", timer.read_us()); } }