Hello world for Rohm BH1726 ALS dual channel sensor. Uses Rohm sensor hal and bh1726 driver.

Dependencies:   mbed rohm-bh1726 rohm-sensor-hal

Fork of rohm-bh1745-hello by Rohm

Committer:
MikkoZ
Date:
Wed Sep 14 07:17:13 2016 +0000
Revision:
5:a8feb1b6e6b5
Parent:
4:a9efa968de28
Child:
7:0baf8142fdef
Initial version of bh1726 hello world.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikkoZ 2:edc916d1a86d 1 /* Copyright 2016 Rohm Semiconductor
MikkoZ 2:edc916d1a86d 2
MikkoZ 2:edc916d1a86d 3 Licensed under the Apache License, Version 2.0 (the "License");
MikkoZ 2:edc916d1a86d 4 you may not use this file except in compliance with the License.
MikkoZ 2:edc916d1a86d 5 You may obtain a copy of the License at
MikkoZ 2:edc916d1a86d 6
MikkoZ 2:edc916d1a86d 7 http://www.apache.org/licenses/LICENSE-2.0
MikkoZ 2:edc916d1a86d 8
MikkoZ 2:edc916d1a86d 9 Unless required by applicable law or agreed to in writing, software
MikkoZ 2:edc916d1a86d 10 distributed under the License is distributed on an "AS IS" BASIS,
MikkoZ 2:edc916d1a86d 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikkoZ 2:edc916d1a86d 12 See the License for the specific language governing permissions and
MikkoZ 2:edc916d1a86d 13 limitations under the License.
MikkoZ 2:edc916d1a86d 14 */
MikkoZ 2:edc916d1a86d 15
MikkoZ 2:edc916d1a86d 16 #include "rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h" //mbed.h, types, DEBUG_print*
MikkoZ 2:edc916d1a86d 17 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
MikkoZ 2:edc916d1a86d 18
MikkoZ 5:a8feb1b6e6b5 19 #include "rohm-bh1726/rohm-bh1726/bh1726_driver.h"
MikkoZ 5:a8feb1b6e6b5 20 #include "rohm-bh1726/rohm-bh1726/bh1726.h"
MikkoZ 2:edc916d1a86d 21
MikkoZ 2:edc916d1a86d 22 Serial pc(USBTX, USBRX);
MikkoZ 2:edc916d1a86d 23
MikkoZ 5:a8feb1b6e6b5 24 void bh1726_print_raw_values(){
MikkoZ 5:a8feb1b6e6b5 25 pc.printf("\nbh1726 library test program.\n\r");
MikkoZ 2:edc916d1a86d 26 I2CCommonBegin();
MikkoZ 2:edc916d1a86d 27
MikkoZ 5:a8feb1b6e6b5 28 bh1726_wait_until_found();
MikkoZ 5:a8feb1b6e6b5 29 bh1726_initial_setup();
MikkoZ 2:edc916d1a86d 30 wait(1);
MikkoZ 5:a8feb1b6e6b5 31 // bh1726_dumpregs(BH1726_REGISTER_DUMP_START, BH1726_REGISTER_DUMP_END);
MikkoZ 2:edc916d1a86d 32
MikkoZ 2:edc916d1a86d 33 while(1) {
MikkoZ 2:edc916d1a86d 34 bool error;
MikkoZ 5:a8feb1b6e6b5 35 uint16_t data[2]; //2 channels of 16-bit data
MikkoZ 2:edc916d1a86d 36
MikkoZ 5:a8feb1b6e6b5 37 error = bh1726_read_data(&data[0]);
MikkoZ 2:edc916d1a86d 38 if (!error) {
MikkoZ 5:a8feb1b6e6b5 39 pc.printf("ALS Data0[%4u], Data1[%4u]\n\r", data[0], data[1]);
MikkoZ 2:edc916d1a86d 40 }
MikkoZ 2:edc916d1a86d 41 else {
MikkoZ 2:edc916d1a86d 42 pc.printf("\n\r");
MikkoZ 2:edc916d1a86d 43 }
MikkoZ 4:a9efa968de28 44 wait(0.2);
MikkoZ 2:edc916d1a86d 45 }
MikkoZ 2:edc916d1a86d 46 }
MikkoZ 2:edc916d1a86d 47
MikkoZ 2:edc916d1a86d 48
MikkoZ 2:edc916d1a86d 49 int main() {
MikkoZ 5:a8feb1b6e6b5 50 bh1726_print_raw_values();
MikkoZ 2:edc916d1a86d 51 }
MikkoZ 2:edc916d1a86d 52