Rohm BH1745 red-green-blue-clear -color sensor hello world. Uses Rohm sensor hal for i2c commands and rohm-bh1745 -driver for sensor specific commands.

Dependencies:   mbed rohm-bh1745 rohm-sensor-hal

Fork of rohm-rpr0521-hello by Rohm

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_classic.cpp Source File

main_classic.cpp

00001 /*   Copyright 2016 Rohm Semiconductor
00002 
00003    Licensed under the Apache License, Version 2.0 (the "License");
00004    you may not use this file except in compliance with the License.
00005    You may obtain a copy of the License at
00006 
00007        http://www.apache.org/licenses/LICENSE-2.0
00008 
00009    Unless required by applicable law or agreed to in writing, software
00010    distributed under the License is distributed on an "AS IS" BASIS,
00011    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012    See the License for the specific language governing permissions and
00013    limitations under the License.
00014 */
00015 
00016 #include "rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h"       //mbed.h, types, DEBUG_print*
00017 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
00018 
00019 #include "rohm-bh1745/rohm-bh1745/bh1745_driver.h"
00020 #include "rohm-bh1745/rohm-bh1745/bh1745.h"
00021 
00022 Serial pc(USBTX, USBRX);
00023 
00024 void bh1745_print_one_value(){
00025     bool error;
00026     uint16_t data[4];       //4 channels of 16-bit data
00027 
00028     error = bh1745_read_data(&data[0]);
00029     if (!error) {
00030         pc.printf("Red[%4u], Green[%4u], Blue[%4u], Clear[%4u]\n\r", data[0], data[1], data[2], data[3]);
00031         }
00032     else {
00033         pc.printf("\n\r");
00034         }
00035 }
00036 
00037 void bh1745_print_raw_values(){
00038     pc.printf("\nbh1745 library test program.\n\r");
00039     I2CCommonBegin();
00040 
00041     bh1745_wait_until_found();
00042     pc.printf("\nSensor found.\n\r");
00043     bh1745_initial_setup();
00044     wait(1);
00045     
00046     while(1) {
00047         bh1745_print_one_value();
00048         wait(0.2);
00049     }
00050 }
00051 
00052 
00053 int main() {
00054     bh1745_print_raw_values();
00055     }
00056