
example for using the rgb_color_sensor class
Diff: main.cpp
- Revision:
- 0:d034f4b3b23c
- Child:
- 3:3649eaf4f954
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jun 25 14:44:44 2014 +0000 @@ -0,0 +1,59 @@ +/* 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()); + } +} \ No newline at end of file