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

main_classic.cpp

Committer:
MikkoZ
Date:
2016-09-12
Revision:
4:a9efa968de28
Parent:
2:edc916d1a86d
Child:
6:cdf8e9ef435d

File content as of revision 4:a9efa968de28:

/*   Copyright 2016 Rohm Semiconductor

   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 "rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h"       //mbed.h, types, DEBUG_print*
#include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"

#include "rohm-bh1745/rohm-bh1745/bh1745_driver.h"
#include "rohm-bh1745/rohm-bh1745/bh1745.h"

Serial pc(USBTX, USBRX);

void bh1745_print_raw_values(){
    pc.printf("\nbh1745 library test program.\n\r");
    I2CCommonBegin();

    bh1745_wait_until_found();
    pc.printf("\nSensor found.\n\r");
    bh1745_initial_setup();
    wait(1);
    
    while(1) {
        bool error;
        uint16_t data[4];       //4 channels of 16-bit data

        error = bh1745_read_data(&data[0]);
        if (!error) {
            pc.printf("Red[%4u], Green[%4u], Blue[%4u], Clear[%4u]\n\r", data[0], data[1], data[2], data[3]);
            }
        else {
            pc.printf("\n\r");
            }
        wait(0.2);
    }
}


int main() {
    bh1745_print_raw_values();
    }